MaterialDesignInXAML / MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.
http://materialdesigninxaml.net
MIT License
15.09k stars 3.42k forks source link

Broken ComboBox when starting a window in a new AppDomain #3316

Open PerfilyevID opened 1 year ago

PerfilyevID commented 1 year ago

Bug explanation

I have a .net48 library (Autodesk Revit plugin) and I need to show window in new AppDomain (to avoid version conflict between different versions of MaterialDesign - other uploaded plugins). Everything looks good, but ComboBoxes are broken, they are not expandable, the only way to change selection is using keyboard arrows.

I also tried running the same Windows without creating a new AppDomain, and everything was fine; Replacing a Global.xaml dictionary with a local one does not affect;

WPF Library

Global.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
        <materialDesign:BundledTheme BaseTheme="Light" PrimaryColor="Green" SecondaryColor="Pink"/>
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

Windows\MainWindow.xaml

<Window x:Class="Module.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes">
    <Window.Resources>
        <ResourceDictionary Source="pack://application:,,,/Module.WPF;component/Global.xaml"/>
    </Window.Resources>
    <Grid>
        <ComboBox>
            <ComboBoxItem>
                <TextBlock>Example #1</TextBlock>
            </ComboBoxItem>
            <ComboBoxItem>
                <TextBlock>Example #2</TextBlock>
            </ComboBoxItem>
        </ComboBox>
    </Grid>
</Window>

Engine library

Plugin.cs : MarshalByRefObject

protected virtual Type _MainWindowType { get; } => typeof(MainWindow);

public virtual void Run(params object[] args)
{
    var thread = new Thread(() =>
    {
        BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
        var window = _MainWindowType.GetConstructors(flags).First().Invoke(args) as Window;
        window.Show();
        Dispatcher.Run();
    });
    thread.SetApartmentState(ApartmentState.STA);
    thread.Start();
}

PluginManager.cs : MarshalByRefObject

public void RunPlugin(PluginInfo pluginInfo, params object[] args)
{
    Plugin plugin = domain.CreateInstanceFromAndUnwrap(pluginInfo.AssemblyPath, pluginInfo.TypeName) as Plugin;
    plugin.Run(args);
}

Version

4.9.0.0

Keboo commented 11 months ago

Though I am not able to reproduce, I did go through the ComboBox popup code and found a reference that I think may be related (PR #3344). I suspect the issue that that the ComboBoxes are expanding but due to the custom positioning code, something is causing the location to be incorrect. Are you able to do a debug build of the library and see what is being returned from the ComboBoxPopup.ComboBoxCustomPopupPlacementCallback method?