Avalonia,样式在更改时不更新

发布于 2025-01-10 10:14:47 字数 1764 浏览 2 评论 0原文

阿瓦洛尼亚做了一些奇怪的事情
使用 AvaloniaApp 模板

public void ToggleTheme(object? sender, RoutedEventArgs e)
    {
        Debug.WriteLine("Mode: " + App.Fluent.Mode.ToString() + " Styles[0]: " + Application.Current!.Styles[0].ToString());
        if (App.Fluent.Mode == FluentThemeMode.Dark)
        {
            App.Fluent.Mode = FluentThemeMode.Light;
        }
        else if (App.Fluent.Mode == FluentThemeMode.Light)
        {
            App.Fluent.Mode = FluentThemeMode.Dark;
        }
        Application.Current!.Styles[0] = App.Fluent;
        Application.Current.Styles[1] = App.DataGridFluent;
    }

单击我的按钮即可获得它
调试输出

Mode: Dark Styles[0]: Avalonia.Themes.Fluent.FluentTheme
Mode: Light Styles[0]: Avalonia.Themes.Fluent.FluentTheme
Mode: Dark Styles[0]: Avalonia.Themes.Fluent.FluentTheme
Mode: Light Styles[0]: Avalonia.Themes.Fluent.FluentTheme

我需要重新加载一些东西吗?
https://github.dev/AvaloniaUI/Avalonia/tree/master/samples/控制目录
使用的代码,将其从组合框更改为按钮

顺便说一句,有人知道 Avalonia.Default 是怎么回事吗?
默认样式还没有实现模式吗?

该事件似乎没有在列表中触发,我可以使用外部解决方法吗?

Application.Current.Styles.CollectionChanged += (s, e) => Debug.WriteLine("Updated");

我可以从外部修改列表以引发项目更改事件吗?

public override void Initialize()
        {
            Styles.Insert(0, Fluent);
            Styles.Insert(1, DataGridFluent);
            AvaloniaXamlLoader.Load(this);
        }

https://github.com/AvaloniaUI/Avalonia/issues/3495 发现了这个问题,不过据说已经修复了

Avalonia doing something odd
using AvaloniaApp template

public void ToggleTheme(object? sender, RoutedEventArgs e)
    {
        Debug.WriteLine("Mode: " + App.Fluent.Mode.ToString() + " Styles[0]: " + Application.Current!.Styles[0].ToString());
        if (App.Fluent.Mode == FluentThemeMode.Dark)
        {
            App.Fluent.Mode = FluentThemeMode.Light;
        }
        else if (App.Fluent.Mode == FluentThemeMode.Light)
        {
            App.Fluent.Mode = FluentThemeMode.Dark;
        }
        Application.Current!.Styles[0] = App.Fluent;
        Application.Current.Styles[1] = App.DataGridFluent;
    }

got it as a click to my button
debug output

Mode: Dark Styles[0]: Avalonia.Themes.Fluent.FluentTheme
Mode: Light Styles[0]: Avalonia.Themes.Fluent.FluentTheme
Mode: Dark Styles[0]: Avalonia.Themes.Fluent.FluentTheme
Mode: Light Styles[0]: Avalonia.Themes.Fluent.FluentTheme

do i have to reload something?
https://github.dev/AvaloniaUI/Avalonia/tree/master/samples/ControlCatalog
code used, changed it from Combobox to button

btw anyone knows what's up with Avalonia.Default?
Are Default styles still not Mode implemented?

It seems that the event is not firing on the list, is there outside workaround i could use?

Application.Current.Styles.CollectionChanged += (s, e) => Debug.WriteLine("Updated");

Can I modify the list from outside to raise an event on item change?

public override void Initialize()
        {
            Styles.Insert(0, Fluent);
            Styles.Insert(1, DataGridFluent);
            AvaloniaXamlLoader.Load(this);
        }

https://github.com/AvaloniaUI/Avalonia/issues/3495
Found this issue but it is said to be fixed

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文