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

Changing Fluent Theme in Runtime Crashes Comboboxes #17917

Open
bugrakurnaz opened this issue Jan 8, 2025 · 0 comments
Open

Changing Fluent Theme in Runtime Crashes Comboboxes #17917

bugrakurnaz opened this issue Jan 8, 2025 · 0 comments
Labels

Comments

@bugrakurnaz
Copy link

Describe the bug

To change the fluent theme of the application, I use the approach of: #12042 (comment)

However, after changing the theme, some controls become unusable. For instance, if a combobox (that was clicked at least once before I change the theme) is clicked, I receive the following error in Visual.cs, line 633:

if (item.VisualParent is { } parent)
{
throw new InvalidOperationException(
$"The control {item.DebugDisplay} already has a visual parent {parent.GetDebugDisplay(false)} " +
$"while trying to add it as a child of {GetDebugDisplay(false)}.");
}

System.InvalidOperationException: 'The control ItemsPresenter (Name = PART_ItemsPresenter) already has a visual parent ScrollContentPresenter (Name = PART_ContentPresenter) while trying to add it as a child of ScrollContentPresenter (Name = PART_ContentPresenter, Host = ScrollViewer).'

I receive similar errors in other ItemsPresenter's as well.

To Reproduce

  1. Open a new Avalonia application.
  2. Click on a combobox.
  3. Change the theme via the following code piece, adapted from Make `FluentTheme` instance with changed color palette, dynamically #12042 (comment)
  Application.Current.Styles.RemoveAt(0);
  Application.Current.Styles.Insert(0, 
    new FluentTheme()
    {
        Palettes =
        {
            [ThemeVariant.Light] = new ColorPaletteResources()
            {
                Accent = Color.Parse("#ffcc4d11"),
                AltHigh = Color.Parse("#ffffffff"),
                AltLow = Color.Parse("#ffffffff"),
                AltMedium = Color.Parse("#ffffffff"),
                AltMediumHigh = Color.Parse("#ffffffff"),
                AltMediumLow = Color.Parse("#ffffffff"),
                BaseHigh = Color.Parse("#ff000000"),
                BaseLow = Color.Parse("#ff7cbee0"),
                BaseMedium = Color.Parse("#ff3282a8"),
                BaseMediumHigh = Color.Parse("#ff005a83"),
                BaseMediumLow = Color.Parse("#ff196e96"),
                ChromeAltLow = Color.Parse("#ff005a83"),
                ChromeBlackHigh = Color.Parse("#ff000000"),
                ChromeBlackLow = Color.Parse("#ff7cbee0"),
                ChromeBlackMedium = Color.Parse("#ff005a83"),
                ChromeBlackMediumLow = Color.Parse("#ff3282a8"),
                ChromeDisabledHigh = Color.Parse("#ff7cbee0"),
                ChromeDisabledLow = Color.Parse("#ff3282a8"),
                ChromeGray = Color.Parse("#ff196e96"),
                ChromeHigh = Color.Parse("#ff7cbee0"),
                ChromeLow = Color.Parse("#ffc1e9fe"),
                ChromeMedium = Color.Parse("#ffb3e0f8"),
                ChromeMediumLow = Color.Parse("#ffc1e9fe"),
                ChromeWhite = Color.Parse("#ffffffff"),
                ListLow = Color.Parse("#ffb3e0f8"),
                ListMedium = Color.Parse("#ff7cbee0"),
                RegionColor = Color.Parse("#ffcfeaff")
            },
            [ThemeVariant.Dark] = new ColorPaletteResources()
            {
                Accent = Color.Parse("#ffcc4d11"),
                AltHigh = Color.Parse("#ff000000"),
                AltLow = Color.Parse("#ff000000"),
                AltMedium = Color.Parse("#ff000000"),
                AltMediumHigh = Color.Parse("#ff000000"),
                AltMediumLow = Color.Parse("#ff000000"),
                BaseHigh = Color.Parse("#ffffffff"),
                BaseLow = Color.Parse("#ff2f7bad"),
                BaseMedium = Color.Parse("#ff8dbfdf"),
                BaseMediumHigh = Color.Parse("#ffa5d0ec"),
                BaseMediumLow = Color.Parse("#ff5e9dc6"),
                ChromeAltLow = Color.Parse("#ffa5d0ec"),
                ChromeBlackHigh = Color.Parse("#ff000000"),
                ChromeBlackLow = Color.Parse("#ffa5d0ec"),
                ChromeBlackMedium = Color.Parse("#ff000000"),
                ChromeBlackMediumLow = Color.Parse("#ff000000"),
                ChromeDisabledHigh = Color.Parse("#ff2f7bad"),
                ChromeDisabledLow = Color.Parse("#ff8dbfdf"),
                ChromeGray = Color.Parse("#ff76aed3"),
                ChromeHigh = Color.Parse("#ff76aed3"),
                ChromeLow = Color.Parse("#ff093b73"),
                ChromeMedium = Color.Parse("#ff134b82"),
                ChromeMediumLow = Color.Parse("#ff266b9f"),
                ChromeWhite = Color.Parse("#ffffffff"),
                ListLow = Color.Parse("#ff134b82"),
                ListMedium = Color.Parse("#ff2f7bad"),
                RegionColor = Color.Parse("#ff0d2644")
            }
        }
    }
);
  1. Click on the combobox again, the error will crash the application.

Expected behavior

Color palette changes as expected, however app should not crash.

Avalonia version

11.2.3

OS

Windows

Additional context

If I remove the ScrollViewer from default combobox theme, ComboBox Theme, application does not crash. However, I suspect this problem happens with other controls that include a ScrollViewer as well, and ScrollViewer is not unnecessary.

@bugrakurnaz bugrakurnaz added the bug label Jan 8, 2025
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

1 participant