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

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

Open
PerfilyevID opened this issue Sep 5, 2023 · 1 comment
Open

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

PerfilyevID opened this issue Sep 5, 2023 · 1 comment
Labels
bug evaluation required Items is pending review or evaluation by the team

Comments

@PerfilyevID
Copy link

PerfilyevID commented Sep 5, 2023

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

@PerfilyevID PerfilyevID added bug evaluation required Items is pending review or evaluation by the team labels Sep 5, 2023
@PerfilyevID PerfilyevID changed the title ComboBox doesn't expand running from another AppDomain Broken ComboBox when starting a window in a new AppDomain Sep 6, 2023
Keboo added a commit that referenced this issue Oct 22, 2023
@Keboo
Copy link
Member

Keboo commented Oct 22, 2023

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?

Keboo added a commit that referenced this issue Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug evaluation required Items is pending review or evaluation by the team
Projects
None yet
Development

No branches or pull requests

2 participants