Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application crashes when switching tabs #15593

Open
Zaspard opened this issue May 3, 2024 · 3 comments
Open

Application crashes when switching tabs #15593

Zaspard opened this issue May 3, 2024 · 3 comments
Labels
area-xaml by-design The behavior reported in the issue is actually correct.

Comments

@Zaspard
Copy link

Zaspard commented May 3, 2024

Describe the bug

When switching a tab in TabControl, the open TablItem is detached from the visual tree. Some child items of this TablItem try to redraw due to axaml binding, which causes an error to occur

  • ItemsControl ItemsSource="{Binding SomeItems, RelativeSource={RelativeSource AncestorType=local:TestTemplatedControl}, Mode=OneWay}"
  • Style Selector="^[(local|TestTemplatedControl.SomeBoolValue)=True]"

To Reproduce

Project for test: Sample.zip

  1. Run project
  2. Click on tab 0
  3. Click on another tab (-1 or 1)
Avalonia.AvaloniaInternalException
  HResult=0x80131500
  Message=Visual is atached to visual tree but root could not be found.
  Source=Avalonia.Base
  StackTrace:
   at Avalonia.Visual.SetVisualParent(Visual value)
   at Avalonia.Visual.SetVisualParent(IList children, Visual parent)
   at Avalonia.Visual.VisualChildrenChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Avalonia.Collections.AvaloniaList`1.Add(T item)
   at Avalonia.Controls.Presenters.ContentPresenter.UpdateChild(Object content)
   at Avalonia.Controls.Presenters.ContentPresenter.UpdateChild()
   at Avalonia.Controls.Presenters.ContentPresenter.ContentChanged(AvaloniaPropertyChangedEventArgs e)
   at Avalonia.Controls.Presenters.ContentPresenter.OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
   at Avalonia.Animation.Animatable.OnPropertyChangedCore(AvaloniaPropertyChangedEventArgs change)
   at Avalonia.AvaloniaObject.RaisePropertyChanged[T](AvaloniaProperty`1 property, Optional`1 oldValue, BindingValue`1 newValue, BindingPriority priority, Boolean isEffectiveValue)
   at Avalonia.PropertyStore.EffectiveValue`1.SetAndRaiseCore(ValueStore owner, StyledProperty`1 property, T value, BindingPriority priority, Boolean isOverriddenCurrentValue, Boolean isCoercedDefaultValue)
   at Avalonia.PropertyStore.EffectiveValue`1.SetAndRaise(ValueStore owner, IValueEntry value, BindingPriority priority)
   at Avalonia.PropertyStore.ValueStore.ReevaluateEffectiveValue(AvaloniaProperty property, EffectiveValue current, IValueEntry changedValueEntry, Boolean ignoreLocalValue)
   at Avalonia.Styling.Activators.StyleActivatorBase.ReevaluateIsActive()
   at Avalonia.Styling.Activators.PropertyEqualsActivator.System.IObserver<System.Object>.OnNext(Object value)
   at Avalonia.Reactive.LightweightObservableBase`1.PublishNext(T value)
   at Avalonia.Reactive.AvaloniaPropertyObservable`2.PublishNewValue(TResult newValue)
   at Avalonia.Reactive.AvaloniaPropertyObservable`2.PropertyChanged(Object sender, AvaloniaPropertyChangedEventArgs e)
   at Avalonia.AvaloniaObject.RaisePropertyChanged[T](AvaloniaProperty`1 property, Optional`1 oldValue, BindingValue`1 newValue, BindingPriority priority, Boolean isEffectiveValue)
   at Avalonia.PropertyStore.EffectiveValue`1.RaiseInheritedValueChanged(AvaloniaObject owner, AvaloniaProperty property, EffectiveValue oldValue, EffectiveValue newValue)
   at Avalonia.PropertyStore.ValueStore.InheritedValueChanged(AvaloniaProperty property, EffectiveValue oldValue, EffectiveValue newValue)
   at Avalonia.PropertyStore.ValueStore.InheritedValueChanged(AvaloniaProperty property, EffectiveValue oldValue, EffectiveValue newValue)
   at Avalonia.PropertyStore.ValueStore.SetInheritanceParent(AvaloniaObject newParent)
   at Avalonia.AvaloniaObject.set_InheritanceParent(AvaloniaObject value)
   at Avalonia.StyledElement.Avalonia.Controls.ISetLogicalParent.SetParent(ILogical parent)
   at Avalonia.StyledElement.ClearLogicalParent(IList children)
   at Avalonia.StyledElement.LogicalChildrenCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Avalonia.Visual.LogicalChildrenCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Avalonia.Collections.AvaloniaList`1.NotifyRemove(T item, Int32 index)
   at Avalonia.Collections.AvaloniaList`1.Remove(T item)
   at Avalonia.Controls.ItemsControl.RemoveLogicalChild(Control c)
   at Avalonia.Controls.Presenters.PanelContainerGenerator.<OnItemsChanged>g__Remove|5_1(Int32 index, Int32 count, <>c__DisplayClass5_0& )
   at Avalonia.Controls.Presenters.PanelContainerGenerator.OnItemsChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Avalonia.Controls.ItemsSourceView.RaiseCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Avalonia.Controls.ItemCollection.SetSource(IEnumerable source)
   at Avalonia.Controls.ItemCollection.SetItemsSource(IEnumerable value)
   at Avalonia.Controls.ItemsControl.OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
   at Avalonia.Animation.Animatable.OnPropertyChangedCore(AvaloniaPropertyChangedEventArgs change)
   at Avalonia.AvaloniaObject.RaisePropertyChanged[T](AvaloniaProperty`1 property, Optional`1 oldValue, BindingValue`1 newValue, BindingPriority priority, Boolean isEffectiveValue)
   at Avalonia.PropertyStore.EffectiveValue`1.SetAndRaiseCore(ValueStore owner, StyledProperty`1 property, T value, BindingPriority priority, Boolean isOverriddenCurrentValue, Boolean isCoercedDefaultValue)
   at Avalonia.PropertyStore.EffectiveValue`1.SetLocalValueAndRaise(ValueStore owner, StyledProperty`1 property, T value)
   at Avalonia.PropertyStore.ValueStore.SetLocalValue[T](StyledProperty`1 property, T value)
   at Avalonia.PropertyStore.LocalValueBindingObserverBase`1.<OnNext>g__Execute|15_0(LocalValueBindingObserverBase`1 instance, BindingValue`1 value)
   at Avalonia.PropertyStore.LocalValueBindingObserverBase`1.OnNext(BindingValue`1 value)
   at Avalonia.PropertyStore.LocalValueBindingObserver`1.OnNext(Object value)
   at Avalonia.Reactive.LightweightObservableBase`1.PublishNext(T value)
   at Avalonia.Data.Core.BindingExpression.InnerListener.OnNext(Object value)
   at Avalonia.Reactive.LightweightObservableBase`1.PublishNext(T value)
   at Avalonia.Data.Core.ExpressionObserver.ValueChanged(Object value)
   at Avalonia.Data.Core.ExpressionNode.ValueChanged(Object value, Boolean notify)
   at Avalonia.Data.Core.ExpressionNode.ValueChanged(Object value)
   at Avalonia.Data.Core.ExpressionNode.StartListening()
   at Avalonia.Data.Core.ExpressionNode.set_Target(WeakReference`1 value)
   at Avalonia.Data.Core.ExpressionObserver.<StartRoot>b__33_0(Object x)
   at Avalonia.Reactive.LightweightObservableBase`1.PublishNext(T value)
   at Avalonia.VisualTree.VisualLocator.VisualTracker.AttachedDetached(Object sender, VisualTreeAttachmentEventArgs e)
   at Avalonia.Visual.OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
   at Avalonia.Layout.Layoutable.OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
   at Avalonia.Input.InputElement.OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
   at Avalonia.Controls.Control.OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
   at Avalonia.Visual.OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
   at Avalonia.Layout.Layoutable.OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
   at Avalonia.Input.InputElement.OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
   at Avalonia.Controls.Control.OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
   at Avalonia.Visual.SetVisualParent(Visual value)
   at Avalonia.Visual.SetVisualParent(IList children, Visual parent)
   at Avalonia.Visual.VisualChildrenChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Avalonia.Collections.AvaloniaList`1.NotifyRemove(T item, Int32 index)
   at Avalonia.Collections.AvaloniaList`1.Remove(T item)
   at Avalonia.Controls.Presenters.ContentPresenter.UpdateChild(Object content)
   at Avalonia.Controls.Presenters.ContentPresenter.ContentChanged(AvaloniaPropertyChangedEventArgs e)
   at Avalonia.Controls.Presenters.ContentPresenter.OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
   at Avalonia.Animation.Animatable.OnPropertyChangedCore(AvaloniaPropertyChangedEventArgs change)
   at Avalonia.AvaloniaObject.RaisePropertyChanged[T](AvaloniaProperty`1 property, Optional`1 oldValue, BindingValue`1 newValue, BindingPriority priority, Boolean isEffectiveValue)
   at Avalonia.PropertyStore.EffectiveValue`1.SetAndRaiseCore(ValueStore owner, StyledProperty`1 property, T value, BindingPriority priority, Boolean isOverriddenCurrentValue, Boolean isCoercedDefaultValue)
   at Avalonia.PropertyStore.EffectiveValue`1.SetAndRaise(ValueStore owner, IValueEntry value, BindingPriority priority)
   at Avalonia.PropertyStore.ValueStore.ReevaluateEffectiveValue(AvaloniaProperty property, EffectiveValue current, IValueEntry changedValueEntry, Boolean ignoreLocalValue)
   at Avalonia.PropertyStore.ValueStore.OnBindingValueChanged(IValueEntry entry, BindingPriority priority)
   at Avalonia.PropertyStore.BindingEntryBase`2.<SetValue>g__Execute|37_0(BindingEntryBase`2 instance, BindingValue`1 value)
   at Avalonia.PropertyStore.BindingEntryBase`2.SetValue(BindingValue`1 value)
   at Avalonia.PropertyStore.BindingEntryBase`2.OnNext(TSource value)
   at Avalonia.Data.TemplateBinding.PublishValue()
   at Avalonia.Data.TemplateBinding.TemplatedParentPropertyChanged(Object sender, AvaloniaPropertyChangedEventArgs e)
   at Avalonia.AvaloniaObject.RaisePropertyChanged[T](AvaloniaProperty`1 property, Optional`1 oldValue, BindingValue`1 newValue, BindingPriority priority, Boolean isEffectiveValue)
   at Avalonia.AvaloniaObject.SetAndRaise[T](DirectPropertyBase`1 property, T& field, T value)
   at Avalonia.Controls.TabControl.set_SelectedContent(Object value)
   at Avalonia.Controls.TabControl.<UpdateSelectedContent>b__45_0(Object v)
   at Avalonia.Reactive.AvaloniaPropertyObservable`2.Subscribed(IObserver`1 observer, Boolean first)
   at Avalonia.Reactive.LightweightObservableBase`1.Subscribe(IObserver`1 observer)
   at Avalonia.Reactive.Observable.Subscribe[T](IObservable`1 source, Action`1 action)
   at Avalonia.Controls.TabControl.UpdateSelectedContent(Control container)
   at Avalonia.Controls.TabControl.<>c.<.cctor>b__10_0(TabControl x, AvaloniaPropertyChangedEventArgs e)
   at Avalonia.AvaloniaObjectExtensions.ClassHandlerObserver`1.OnNext(AvaloniaPropertyChangedEventArgs value)
   at Avalonia.Reactive.LightweightObservableBase`1.PublishNext(T value)
   at Avalonia.AvaloniaObject.RaisePropertyChanged[T](AvaloniaProperty`1 property, Optional`1 oldValue, BindingValue`1 newValue, BindingPriority priority, Boolean isEffectiveValue)
   at Avalonia.AvaloniaObject.RaisePropertyChanged[T](DirectPropertyBase`1 property, T oldValue, T newValue)
   at Avalonia.Controls.Primitives.SelectingItemsControl.OnSelectionModelPropertyChanged(Object sender, PropertyChangedEventArgs e)
   at Avalonia.Controls.Selection.SelectionModel`1.RaisePropertyChanged(String propertyName)
   at Avalonia.Controls.Selection.SelectionModel`1.CommitOperation(Operation operation, Boolean raisePropertyChanged)
   at Avalonia.Controls.Selection.SelectionModel`1.EndBatchUpdate()
   at Avalonia.Controls.Selection.SelectionModelExtensions.BatchUpdateOperation.Dispose()
   at Avalonia.Controls.Primitives.SelectingItemsControl.UpdateSelection(Int32 index, Boolean select, Boolean rangeModifier, Boolean toggleModifier, Boolean rightButton, Boolean fromFocus)
   at Avalonia.Controls.Primitives.SelectingItemsControl.UpdateSelection(Control container, Boolean select, Boolean rangeModifier, Boolean toggleModifier, Boolean rightButton, Boolean fromFocus)
   at Avalonia.Controls.Primitives.SelectingItemsControl.UpdateSelectionFromEventSource(Object eventSource, Boolean select, Boolean rangeModifier, Boolean toggleModifier, Boolean rightButton, Boolean fromFocus)
   at Avalonia.Controls.TabControl.OnPointerPressed(PointerPressedEventArgs e)
   at Avalonia.Input.InputElement.<>c.<.cctor>b__32_8(InputElement x, PointerPressedEventArgs e)
   at Avalonia.Reactive.LightweightObservableBase`1.PublishNext(T value)
   at Avalonia.Interactivity.EventRoute.RaiseEventImpl(RoutedEventArgs e)
   at Avalonia.Interactivity.Interactive.RaiseEvent(RoutedEventArgs e)
   at Avalonia.Input.MouseDevice.MouseDown(IMouseDevice device, UInt64 timestamp, IInputElement root, Point p, PointerPointProperties properties, KeyModifiers inputModifiers, IInputElement hitTest)
   at Avalonia.Input.MouseDevice.ProcessRawEvent(RawPointerEventArgs e)
   at Avalonia.Controls.TopLevel.HandleInput(RawInputEventArgs e)
   at Avalonia.Win32.WindowImpl.AppWndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
   at Avalonia.Win32.WindowImpl.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
   at Avalonia.Win32.Interop.UnmanagedMethods.DispatchMessage(MSG& lpmsg)
   at Avalonia.Win32.Win32DispatcherImpl.RunLoop(CancellationToken cancellationToken)
   at Avalonia.Threading.DispatcherFrame.Run(IControlledDispatcherImpl impl)
   at Avalonia.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken)
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args)
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder builder, String[] args, Action`1 lifetimeBuilder)
   at AvaloniaApplication1.Program.Main(String[] args)

Expected behavior

No response

Avalonia version

11.0.10

OS

Windows

Additional context

in 11.1.0-beta2 error is the same

@Zaspard Zaspard added the bug label May 3, 2024
@timunie
Copy link
Contributor

timunie commented May 3, 2024

why not use {TemplateBinding SomeItems}?

@Zaspard
Copy link
Author

Zaspard commented May 3, 2024

idk :) We found this situation in our project. Application works correctly if use TemplateBinding or fill collection from code-behinde.
You can close issue if you want, but someone may encounter the same situation

@timunie timunie added by-design The behavior reported in the issue is actually correct. area-xaml and removed bug labels May 3, 2024
@timunie
Copy link
Contributor

timunie commented May 3, 2024

Should be added to #13707 instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-xaml by-design The behavior reported in the issue is actually correct.
Projects
None yet
Development

No branches or pull requests

2 participants