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

[Bug] ComboBox throws "The control already has a visual parent" error when it's pressed #5441

Closed
PieroCastillo opened this issue Feb 8, 2021 · 5 comments
Labels

Comments

@PieroCastillo
Copy link

Describe the bug
I tried to make a ThemeChanger (like

<ComboBox x:Name="Themes" SelectedIndex="0">
<ComboBoxItem>Fluent - Light</ComboBoxItem>
<ComboBoxItem>Fluent - Dark</ComboBoxItem>
<ComboBoxItem>Simple - Light</ComboBoxItem>
<ComboBoxItem>Simple - Dark</ComboBoxItem>
</ComboBox>
) but when I press throws an error.

To Reproduce
I don't know exactly the causes, so, I'm going to put the code:
App.xaml.cs
MainWindow.xaml
MainWindow.xaml.cs

Expected behavior
Error when the ComboBox is pressed.

Screenshots

Normal App

2021-02-07.22-43-08.mp4

App without custom controls

2021-02-07.22-53-39.mp4

Desktop (please complete the following information):

  • OS: Windows 10 20H2
  • Version : Avalonia 0.10.0 stable
@FoggyFinder
Copy link
Contributor

Duplicate of #4839

@maxkatz6
Copy link
Member

maxkatz6 commented Feb 9, 2021

Duplicate of #4839
But with some additional context

@maxkatz6
Copy link
Member

maxkatz6 commented Feb 9, 2021

@PieroCastillo long story short, the problem is with reusing same combobox items when its template was changed with new children list container.
As a workaround, if you replace your items with binding to Items property and use item template for items, it should be solved.

IIRC problem makes sense only with updating list control template while its open and items can't be reused.

@PieroCastillo
Copy link
Author

@maxkatz6 THANKSSSSSSSSSSS :DDDDDDDDDDDD
With this code is enough:

 <ComboBox SelectedIndex="0"
                VirtualizationMode="None"
                SelectionChanged="ChangeTheme">
     <ComboBox.ItemTemplate>
         <DataTemplate>
            <TextBlock Text="{Binding .}"/>
         </DataTemplate> 
     </ComboBox.ItemTemplate>
    <l:ArrayList>
         <sys:String>Fluent Light</sys:String>
        <sys:String>Fluent Dark</sys:String>
   </l:ArrayList>
</ComboBox>

@PieroCastillo
Copy link
Author

now all that remains is to improve the performance of the style system. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants