miroiu / nodify

Highly performant and modular controls for node-based editors designed for data-binding and MVVM.
https://miroiu.github.io/nodify
MIT License
1.3k stars 208 forks source link

[Bug] Unable to dynamically switch themes #68

Closed MakesYT closed 1 year ago

MakesYT commented 1 year ago

Describe the bug When I modify the theme by modifying the dictionary theme path, some controls cannot be changed image Light to Dark image Dark to Light image

After reopen image

To Reproduce


        Collection<ResourceDictionary> applicationDictionaries = Application
            .Current
            .Resources
            .MergedDictionaries;

        if (applicationDictionaries.Count == 0)
        {
            return;
        }

        for (var i = 0; i < applicationDictionaries.Count; i++)
        {
            string sourceUri;

            if (applicationDictionaries[i]?.Source != null)
            {
                sourceUri = applicationDictionaries[i].Source.ToString().ToLower().Trim();

                if (sourceUri.Contains("pack://application:,,,/nodify;component"))
                {
                    switch (theme)
                    {
                        case ApplicationTheme.Dark:
                            applicationDictionaries[i] = new()
                            {
                                Source = new Uri("pack://application:,,,/Nodify;component/Themes/Dark.xaml",
                                    UriKind.Absolute)
                            };
                            break;
                        case ApplicationTheme.Light:
                            applicationDictionaries[i] = new()
                            {
                                Source = new Uri("pack://application:,,,/Nodify;component/Themes/light.xaml",
                                    UriKind.Absolute)
                            };
                            break;
                    }

                    break;
                }
            }
        }

Expected behavior A clear and concise description of what you expected to happen. image to image Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

miroiu commented 1 year ago

Hi, I don't think this is a bug for nodify. Changing themes at runtime should be supported but it's up to you how you implement it.

You can check out the example apps (CTR+T to change the theme if there's no button for it in the UI). Last time I checked, I could change the theme just fine.

Make sure you unload the previous theme before loading the new theme.

You can try doing something similar to what I did here: https://github.com/miroiu/nodify/blob/master/Examples/Nodify.Shared/ThemeManager.cs

MakesYT commented 1 year ago

Hi, I don't think this is a bug for nodify. Changing themes at runtime should be supported but it's up to you how you implement it.嗨,我不认为这是点头的错误。应该支持在运行时更改主题,但这取决于您如何实现它。

You can check out the example apps (CTR+T to change the theme if there's no button for it in the UI). Last time I checked, I could change the theme just fine.您可以查看示例应用程序(如果 UI 中没有按钮,则使用 CTR+T 更改主题)。上次我检查时,我可以很好地更改主题。

Make sure you unload the previous theme before loading the new theme.请确保在加载新主题之前卸载以前的主题。

You can try doing something similar to what I did here: https://github.com/miroiu/nodify/blob/master/Examples/Nodify.Shared/ThemeManager.cs您可以尝试执行类似于我在这里所做的操作:https://github.com/miroiu/nodify/blob/master/Examples/Nodify.Shared/ThemeManager.cs

I confirm that I have completed the complete switch because I directly modified the Url path of the old Theme resource dictionary. And the Node theme switch is successful, only the NodifyEditor background switch failed

MakesYT commented 1 year ago

Oh,I know the reason,I uesd

<nodify:NodifyEditor.Background>
        <StaticResource ResourceKey="SmallGridLinesDrawingBrush"/>
</nodify:NodifyEditor.Background>

thanks for your help