-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
the control already has a visual parent Error #4265
Comments
I am experiencing this issue also. I'm on Windows 10, v0.10.0-preview1 (although I also tried 0.9.999-cibuild0008974 and it still happens). In my case, all of the items were added to the ListBox in XAML. The problem seems to be with ListBox scrolling, possibly item virtualization. For me:
|
I am experiencing this issue when resizing my Window.
|
Virtualization can't properly work with hardcoded control items instead of MVVM-like approach with item sources and templates. |
@maxkatz6 I see your solution response, I know you suggested to set "VirtualizationMode="None"", however, I don't know where to put that. I attempted to put it in several places, but no element seemed to recognize the property. For reference, I'm getting the error on a MenuItem click. **Edit** |
@General-Ridley same exception can't possibly happen if virtualization is disabled. To disable virtualization you need to change VirtualizationMode property on ItemsPresenter. ComboBox has a property for convenience that also changes virtualization mode of the item presenter inside. I haven't tested, but something like this should change this mode for the menu item as well:
|
@maxkatz6 thanks for the reply. I attempted using the styles as per your recommendation. However, the error persisted for me. The gist of it is, I have the style you gave in the Window.Styles element. And later in the axaml I have the Menu and a few nested MenuItem elements. I'm using the menu to allow the user to toggle the app's theme from Light to Dark. It will work on the first go. But if the user tries to toggle back, the app crashes on the MenuItem that is the parent of the MenuItems that toggle the theme. I can show you my code setup. And I have the stacktrace; it is sliiiiightly different. But I'm not sure if it's appropriate to continue using this issue to discuss it here, or open a new issue. Which would you prefer? |
Сильно переписал определение минимальных размеров элементов схемы. Дописал VirtualizationMode="None" к каждому ListBox'у в качестве багофикса явного бага авалонии: AvaloniaUI/Avalonia#4265 Разумеется своим умом до такого решения я бы впринципе никогда в жизни бы не дошёл, без жёстких навыков дизассемблерщика кншн XD
Сильно переписал определение минимальных размеров элементов схемы. Дописал VirtualizationMode="None" к каждому ListBox'у в качестве багофикса явного бага авалонии: AvaloniaUI/Avalonia#4265 Разумеется своим умом до такого решения я бы впринципе никогда в жизни бы не дошёл, без жёстких навыков дизассемблерщика кншн XD
Сильно переписал определение минимальных размеров элементов схемы. Дописал VirtualizationMode="None" к каждому ListBox'у в качестве багофикса явного бага авалонии: AvaloniaUI/Avalonia#4265 Разумеется своим умом до такого решения я бы впринципе никогда в жизни бы не дошёл, без жёстких навыков дизассемблерщика кншн XD
Сильно переписал определение минимальных размеров элементов схемы. Дописал VirtualizationMode="None" к каждому ListBox'у в качестве багофикса явного бага авалонии: AvaloniaUI/Avalonia#4265 Разумеется своим умом до такого решения я бы впринципе никогда в жизни бы не дошёл, без жёстких навыков дизассемблерщика кншн XD
Сильно переписал определение минимальных размеров элементов схемы. Дописал VirtualizationMode="None" к каждому ListBox'у в качестве багофикса явного бага авалонии: AvaloniaUI/Avalonia#4265 Разумеется своим умом до такого решения я бы впринципе никогда в жизни бы не дошёл, без жёстких навыков дизассемблерщика кншн XD
Сильно переписал определение минимальных размеров элементов схемы. Дописал VirtualizationMode="None" к каждому ListBox'у в качестве багофикса явного бага авалонии: AvaloniaUI/Avalonia#4265 Разумеется своим умом до такого решения я бы впринципе никогда в жизни бы не дошёл, без жёстких навыков дизассемблерщика кншн XD
I tried to add a lot of button to a ListBox But I keep getting this error : the control already has a visual parent
The error is trigered from here:
public static void Main(string[] args) => BuildAvaloniaApp() .StartWithClassicDesktopLifetime(args);
the StackTrace :
at Avalonia.Visual.ValidateVisualChild(IVisual c) at Avalonia.Collections.AvaloniaList
1.Add(T item)at Avalonia.Controls.Presenters.ContentPresenter.UpdateChild()
at Avalonia.Controls.Presenters.ContentPresenter.ContentChanged(AvaloniaPropertyChangedEventArgs e)
at Avalonia.Controls.Presenters.ContentPresenter.<>c.<.cctor>b__14_0(ContentPresenter x, AvaloniaPropertyChangedEventArgs e)
at System.Reactive.Subjects.Subject
1.OnNext(T value) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Subjects\Subject.cs:line 148 at Avalonia.AvaloniaObject.RaisePropertyChanged(AvaloniaProperty property, Object oldValue, Object newValue, BindingPriority priority) at Avalonia.AvaloniaObject.PriorityValueChanged(AvaloniaProperty property, Int32 priority, Object oldValue, Object newValue) at Avalonia.PriorityValue.SetAndNotify(ValueTuple
2& backing, ValueTuple2 update) at Avalonia.PriorityValue.Avalonia.Utilities.ISetAndNotifyHandler<(System.Object,System.Int32)>.HandleSetAndNotify(AvaloniaProperty property, ValueTuple
2& backing, ValueTuple2 value) at Avalonia.Utilities.DeferredSetter
1.SetAndNotifyCallback[TValue](AvaloniaProperty property, ISetAndNotifyHandler1 setAndNotifyHandler, TValue& backing, TValue value) at Avalonia.PriorityValue.UpdateValue(Object value, Int32 priority) at Avalonia.Reactive.SingleSubscriberObservableBase
1.PublishNext(T value)at Avalonia.Data.TemplateBinding.PublishValue()
at Avalonia.AvaloniaObject.RaisePropertyChanged(AvaloniaProperty property, Object oldValue, Object newValue, BindingPriority priority)
at Avalonia.AvaloniaObject.PriorityValueChanged(AvaloniaProperty property, Int32 priority, Object oldValue, Object newValue)
at Avalonia.PriorityValue.SetAndNotify(ValueTuple
2& backing, ValueTuple
2 update)at Avalonia.PriorityValue.Avalonia.Utilities.ISetAndNotifyHandler<(System.Object,System.Int32)>.HandleSetAndNotify(AvaloniaProperty property, ValueTuple
2& backing, ValueTuple
2 value)at Avalonia.Utilities.DeferredSetter
1.SetAndNotifyCallback[TValue](AvaloniaProperty property, ISetAndNotifyHandler
1 setAndNotifyHandler, TValue& backing, TValue value)at Avalonia.PriorityValue.UpdateValue(Object value, Int32 priority)
at Avalonia.ValueStore.AddValue(AvaloniaProperty property, Object value, Int32 priority)
at Avalonia.AvaloniaObject.SetStyledValue(AvaloniaProperty property, Object value, BindingPriority priority)
at Avalonia.AvaloniaObject.SetValue(AvaloniaProperty property, Object value, BindingPriority priority)
at Avalonia.Controls.Generators.ItemContainerGenerator
1.TryRecycle(Int32 oldIndex, Int32 newIndex, Object item) at Avalonia.Controls.Presenters.ItemVirtualizerSimple.RecycleContainersForMove(Int32 delta) at Avalonia.Controls.Presenters.ItemVirtualizerSimple.set_OffsetValue(Double value) at Avalonia.Controls.Presenters.ItemVirtualizer.set_Offset(Vector value) at Avalonia.Controls.Presenters.ItemsPresenter.Avalonia.Controls.Primitives.IScrollable.set_Offset(Vector value) at Avalonia.Controls.Presenters.ScrollContentPresenter.<>c__DisplayClass38_0.<UpdateScrollableSubscription>b__3(Vector x) at System.Reactive.AnonymousSafeObserver
1.OnNext(T value) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\AnonymousSafeObserver.cs:line 44at System.Reactive.Sink
1.ForwardOnNext(TTarget value) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Internal\Sink.cs:line 50 at System.Reactive.Linq.ObservableImpl.Skip
1.Count._.OnNext(TSource value) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Linq\Observable\Skip.cs:line 59at Avalonia.Reactive.LightweightObservableBase
1.PublishNext(T value) at Avalonia.Reactive.AvaloniaPropertyObservable
1.PropertyChanged(Object sender, AvaloniaPropertyChangedEventArgs e)at Avalonia.AvaloniaObject.RaisePropertyChanged(AvaloniaProperty property, Object oldValue, Object newValue, BindingPriority priority)
at Avalonia.Utilities.DeferredSetter
1.SetAndRaisePropertyChanged(AvaloniaObject source, AvaloniaProperty
1 property, TSetRecord& backing, TSetRecord value)at Avalonia.Utilities.DeferredSetter
1.SetAndNotify(AvaloniaObject source, AvaloniaProperty
1 property, TSetRecord& backing, TSetRecord value)at Avalonia.AvaloniaObject.SetAndRaise[T](AvaloniaProperty
1 property, T& field, T value) at Avalonia.Controls.Presenters.ScrollContentPresenter.set_Offset(Vector value) at Avalonia.Controls.Presenters.ScrollContentPresenter.<>c.<.cctor>b__12_8(ScrollContentPresenter o, Vector v) at Avalonia.DirectProperty
2.Avalonia.IDirectPropertyAccessor.SetValue(IAvaloniaObject instance, Object value)at Avalonia.AvaloniaObject.<>c__DisplayClass54_0.g__Set|0()
at Avalonia.AvaloniaObject.SetDirectValue(AvaloniaProperty property, Object value)
at Avalonia.AvaloniaObject.DirectBindingSubscription.OnNext(Object value)
at Avalonia.Reactive.SingleSubscriberObservableBase
1.PublishNext(T value) at Avalonia.Data.TemplateBinding.PublishValue() at Avalonia.AvaloniaObject.RaisePropertyChanged(AvaloniaProperty property, Object oldValue, Object newValue, BindingPriority priority) at Avalonia.Utilities.DeferredSetter
1.SetAndRaisePropertyChanged(AvaloniaObject source, AvaloniaProperty1 property, TSetRecord& backing, TSetRecord value) at Avalonia.Utilities.DeferredSetter
1.SetAndNotify(AvaloniaObject source, AvaloniaProperty1 property, TSetRecord& backing, TSetRecord value) at Avalonia.AvaloniaObject.SetAndRaise[T](AvaloniaProperty
1 property, T& field, T value)at Avalonia.Controls.ScrollViewer.set_Offset(Vector value)
at Avalonia.Controls.ScrollViewer.set_VerticalScrollBarValue(Double value)
at Avalonia.Controls.ScrollViewer.<>c.<.cctor>b__16_16(ScrollViewer o, Double v)
at Avalonia.DirectProperty
2.Avalonia.IDirectPropertyAccessor.SetValue(IAvaloniaObject instance, Object value) at Avalonia.AvaloniaObject.<>c__DisplayClass54_0.<SetDirectValue>g__Set|0() at Avalonia.AvaloniaObject.SetDirectValue(AvaloniaProperty property, Object value) at Avalonia.AvaloniaObject.SetValue(AvaloniaProperty property, Object value, BindingPriority priority) at Avalonia.Data.TemplateBinding.System.IObserver<System.Object>.OnNext(Object value) at Avalonia.Reactive.LightweightObservableBase
1.PublishNext(T value)at Avalonia.AvaloniaObject.RaisePropertyChanged(AvaloniaProperty property, Object oldValue, Object newValue, BindingPriority priority)
at Avalonia.Utilities.DeferredSetter
1.SetAndRaisePropertyChanged(AvaloniaObject source, AvaloniaProperty
1 property, TSetRecord& backing, TSetRecord value)at Avalonia.Utilities.DeferredSetter
1.SetAndNotify(AvaloniaObject source, AvaloniaProperty
1 property, TSetRecord& backing, TSetRecord value)at Avalonia.AvaloniaObject.SetAndRaise[T](AvaloniaProperty
1 property, T& field, T value) at Avalonia.Controls.Primitives.RangeBase.set_Value(Double value) at Avalonia.Controls.Primitives.RangeBase.<>c.<.cctor>b__28_5(RangeBase o, Double v) at Avalonia.DirectProperty
2.Avalonia.IDirectPropertyAccessor.SetValue(IAvaloniaObject instance, Object value)at Avalonia.AvaloniaObject.<>c__DisplayClass54_0.g__Set|0()
at Avalonia.AvaloniaObject.SetDirectValue(AvaloniaProperty property, Object value)
at Avalonia.AvaloniaObject.SetValue(AvaloniaProperty property, Object value, BindingPriority priority)
at Avalonia.Data.TemplateBinding.System.IObserver<System.Object>.OnNext(Object value)
at Avalonia.Reactive.LightweightObservableBase
1.PublishNext(T value) at Avalonia.AvaloniaObject.RaisePropertyChanged(AvaloniaProperty property, Object oldValue, Object newValue, BindingPriority priority) at Avalonia.Utilities.DeferredSetter
1.SetAndRaisePropertyChanged(AvaloniaObject source, AvaloniaProperty1 property, TSetRecord& backing, TSetRecord value) at Avalonia.Utilities.DeferredSetter
1.SetAndNotify(AvaloniaObject source, AvaloniaProperty1 property, TSetRecord& backing, TSetRecord value) at Avalonia.AvaloniaObject.SetAndRaise[T](AvaloniaProperty
1 property, T& field, T value)at Avalonia.Controls.Primitives.Track.set_Value(Double value)
at Avalonia.Controls.Primitives.Track.ThumbDragged(Object sender, VectorEventArgs e)
at Avalonia.Interactivity.Interactive.g__InvokeAdapter|7_0[TEventArgs](Delegate baseHandler, Object sender, RoutedEventArgs args)
at Avalonia.Interactivity.Interactive.RaiseEventImpl(RoutedEventArgs e)
at Avalonia.Interactivity.Interactive.HierarchyTraverser
2.Traverse(IInteractive target) at Avalonia.Interactivity.Interactive.BubbleEvent(RoutedEventArgs e) at Avalonia.Interactivity.Interactive.RaiseEvent(RoutedEventArgs e) at Avalonia.Controls.Primitives.Thumb.OnPointerMoved(PointerEventArgs e) at System.Reactive.AnonymousObserver
1.OnNextCore(T value) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\AnonymousObserver.cs:line 67at System.Reactive.ObserverBase
1.OnNext(T value) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\ObserverBase.cs:line 36 at System.Reactive.Subjects.Subject
1.OnNext(T value) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Subjects\Subject.cs:line 150at Avalonia.Interactivity.Interactive.RaiseEventImpl(RoutedEventArgs e)
at Avalonia.Interactivity.Interactive.HierarchyTraverser
2.Traverse(IInteractive target) at Avalonia.Interactivity.Interactive.BubbleEvent(RoutedEventArgs e) at Avalonia.Interactivity.Interactive.RaiseEvent(RoutedEventArgs e) at Avalonia.Input.MouseDevice.MouseMove(IMouseDevice device, UInt64 timestamp, IInputRoot root, Point p, PointerPointProperties properties, KeyModifiers inputModifiers) at Avalonia.Input.MouseDevice.ProcessRawEvent(RawPointerEventArgs e) at Avalonia.Input.InputManager.ProcessInput(RawInputEventArgs e) at Avalonia.Win32.WindowImpl.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) at Avalonia.Win32.Interop.UnmanagedMethods.DispatchMessage(MSG& lpmsg) at Avalonia.Win32.Win32Platform.RunLoop(CancellationToken cancellationToken) at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken) at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args) at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode) at TestPerf.Program.Main(String[] args) in C:\Users\axel\source\repos\TestPerf\TestPerf\Program.cs:line 13
My Code :
XAML :
`
C# :
`public MainWindow()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
ListBox c = this.FindControl("ControlBlc");
Bitmap r = new Bitmap("aa.png");
ObservableCollection gt = new ObservableCollection< Button >();
for (int g = 0; g < 10000; g++)
{
Button t = new Button();
t.Background = new ImageBrush(r);
t.Width = 50;
t.Height = 50;
The text was updated successfully, but these errors were encountered: