zoukankan      html  css  js  c++  java
  • WPF应用程序的主题颜色如何修改?DevExpress调色板工具很好用

    DevExpress WPF控件调色板允许您将颜色(例如公司颜色)集成到WPF应用程序中并自定义主题中使用的颜色,在此实例中您可以创建自定义调色板或使用预定义调色板。

    DevExpress WPF v21.1完整版下载

    DevExpress WPF入门级教程 - 主题调色板的使用图集1

    Palette是命名颜色的列表,每种颜色都有一个ColorName值和一个Color值,您可以使用ColorName将颜色分配给任意数量的UI元素:

    DevExpress WPF入门级教程 - 主题调色板的使用图集2
    DevExpress WPF入门级教程 - 主题调色板的使用图集2

    注意:您可以使用 WPF 主题设计器来编辑调色板颜色或将其绑定到 UI 元素。

    以下 DevExpress WPF 主题包含的调色板:

    DevExpress WPF入门级教程 - 主题调色板的使用图集3
    预定义的调色板

    Palette Themes包括以下预定义的调色板:

    DevExpress WPF入门级教程 - 主题调色板的使用图集4
    在代码中应用调色板

    注意:当您切换主题时,应用程序不会卸载加载的主题程序集。

    1. 在您的项目中引用 Mono.cecil NuGet 包。

    2. 调用 Theme.RegisterPredefinedPaletteThemes 方法来启用预定义的调色板。

    3. 将 ApplicationThemeHelper.ApplicationThemeName 属性设置为所需的预定义调色板名称和基本主题名称组合。

    C#

    Theme.RegisterPredefinedPaletteThemes();
    ApplicationThemeHelper.ApplicationThemeName = PredefinedThemePalettes.RedWine.Name + Theme.Office2019White.Name;

    VB.NET

    Theme.RegisterPredefinedPaletteThemes()
    ApplicationThemeHelper.ApplicationThemeName = PredefinedThemePalettes.RedWine.Name + Theme.Office2019White.Name

    TIP:您可以使用 Theme.CachePaletteThemes 属性来缓存当前调色板主题程序集,缓存减少了未来应用程序运行的加载时间。

    上面的代码示例为当前主题启用了所有可用的调色板,要启用和应用单个调色板:

    1. 在您的项目中引用 Mono.cecil NuGet 包。

    2. 将调色板和基本主题传递给Theme.CreateTheme方法以创建新主题。

    3. 将主题传递给 Theme.RegisterTheme方法。

    4. 将 ApplicationThemeHelper.ApplicationThemeName 属性设置为主题名称。

    C#

    var palettetheme = Theme.CreateTheme(PredefinedThemePalettes.RedWine, Theme.Office2019White);
    Theme.RegisterTheme(palettetheme);
    ApplicationThemeHelper.ApplicationThemeName = palettetheme.Name;

    VB.NET

    Dim palettetheme = Theme.CreateTheme(PredefinedThemePalettes.RedWine, Theme.Office2019White)
    Theme.RegisterTheme(palettetheme)
    ApplicationThemeHelper.ApplicationThemeName = palettetheme.Name
    在Ribbon库中显示调色板

    您可以在Ribbon Gallery中显示预定义的调色板,来允许用户选择调色板并将其应用于当前主题:

    DevExpress WPF入门级教程 - 主题调色板的使用图集5

    1. 参考 DevExpress.Mvvm.v21.1.dll 程序集。

    2. 在应用程序启动时调用Theme.RegisterPredefinedPaletteThemes 方法以启用这些调色板:

    C#

    public partial class App : Application {
    protected override void OnStartup(StartupEventArgs e) {
    Theme.RegisterPredefinedPaletteThemes();
    base.OnStartup(e);
    }
    }

    VB.NET

    Public Partial Class App
    Inherits Application
    Protected Overrides Sub OnStartup(ByVal e As StartupEventArgs)
    Theme.RegisterPredefinedPaletteThemes()
    MyBase.OnStartup(e)
    End Sub
    End Class

    3. 将 RibbonGalleryItemThemePaletteSelectorBehavior 附加到 RibbonGalleryBarItem:

    XAML

    <dxr:RibbonGalleryBarItem ... >
    <dxmvvm:Interaction.Behaviors>
    <dxr:RibbonGalleryItemThemePaletteSelectorBehavior />
    </dxmvvm:Interaction.Behaviors>
    </dxr:RibbonGalleryBarItem>
    使用 Windows 10 强调色

    您可以使用带有Windows 10 Light主题的Win10 Palette预定义调色板来获取 Windows 10 强调色,并在您的应用程序中使用该颜色。

    DevExpress WPF入门级教程 - 主题调色板的使用图集6

    以下代码示例使用 Windows 10 强调色创建新的 Win10Light 主题,并在应用程序启动时应用该主题:

    C#

    protected override void OnStartup(StartupEventArgs e)
    {
    var accentpalette = new Win10Palette();
    var customtheme = Theme.CreateTheme(accentpalette, Theme.Win10Light);
    Theme.RegisterTheme(customtheme);
    ApplicationThemeHelper.ApplicationThemeName = customtheme.Name;
    base.OnStartup(e);
    }

    VB.NET

    Protected Overrides Sub OnStartup(ByVal e As StartupEventArgs)
    Dim accentpalette = New Win10Palette()
    Dim customtheme = Theme.CreateTheme(accentpalette, Theme.Win10Light)
    Theme.RegisterTheme(customtheme)
    ApplicationThemeHelper.ApplicationThemeName = customtheme.Name
    MyBase.OnStartup(e)
    End Sub

    注意:Win10 Palette仅适用于 Windows 10 操作系统版本,Win10 Palette 中没有找到Windows 强调色,应用程序强调色设置为#FF0078D7。

    自定义调色板

    在代码中编辑调色板

    注意:当您切换主题时,应用程序不会卸载加载的主题程序集。

    将自定义调色板应用于应用程序:

    1. 在您的项目中引用 Mono.cecil NuGet 包。

    2. 创建一个新的 ThemePalette 实例:

    C#

    var custompalette = new ThemePalette("CustomPalette");

    VB.NET

    Dim custompalette = New ThemePalette("CustomPalette")

    ...或基于预定义的调色板创建一个新的 ThemePalette 实例,在这种情况下,新调色板继承了预定义调色板的颜色:

    C#

    var custompalette = new ThemePalette("CustomPalette", PredefinedThemePalettes.RedWine);

    VB.NET

    Dim custompalette = new ThemePalette("CustomPalette", PredefinedThemePalettes.RedWine)

    3. 使用ThemePalette.SetColor方法指定新颜色:

    C#

    custompalette.SetColor("Foreground", (Color)ColorConverter.ConvertFromString("#FFFF7200"));
    custompalette.SetColor("Backstage.Focused", Colors.White);

    VB.NET

    custompalette.SetColor("Foreground", ColorConverter.ConvertFromString("#FF015C9F"))
    custompalette.SetColor("Foreground", Colors.White)

    将调色板和具有调色板支持的主题传递给Theme.CreateTheme 方法来创建新主题:

    C#

    var customtheme = Theme.CreateTheme(custompalette, Theme.Office2016ColorfulSE);

    VB.NET

    Dim customtheme = Theme.CreateTheme(custompalette, Theme.Office2016ColorfulSE)

    将主题传递给Theme.RegisterTheme方法并将ApplicationThemeHelper.ApplicationThemeName设置为主题的名称,来将主题应用于应用程序:

    C#

    var custompalette = new ThemePalette("CustomPalette");
    custompalette.SetColor("Foreground", (Color)ColorConverter.ConvertFromString("#FFFF7200"));
    custompalette.SetColor("Backstage.Focused", Colors.White);
    var customtheme = Theme.CreateTheme(custompalette, Theme.Office2016ColorfulSE);
    Theme.RegisterTheme(customtheme);
    ApplicationThemeHelper.ApplicationThemeName = customtheme.Name;

    VB.NET

    Dim custompalette = New ThemePalette("CustomPalette")
    custompalette.SetColor("Foreground", ColorConverter.ConvertFromString("#FF015C9F"))
    custompalette.SetColor("Backstage.Focused", Colors.White)
    Dim customtheme = Theme.CreateTheme(custompalette, Theme.Office2016ColorfulSE)
    Theme.RegisterTheme(customtheme)
    ApplicationThemeHelper.ApplicationThemeName = customtheme.Name
    局限性

    #在使用单个文件部署的 .NET 5 应用程序中在运行时更改主题
    DevExpress WPF 主题程序集必须提取到磁盘,发布 .NET 5 应用程序(PublishSingleFile 为 true)时,将项目文件中的 IncludeAllContentForSelfExtract 选项设置为 true,这将允许用户在运行时应用调色板。

    XAML

    <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
    <Nullable>enable</Nullable>
    <PublishSingleFile>true</PublishSingleFile>
    <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
    </PropertyGroup>

    DevExpress WPF | 下载试用

    DevExpress WPF拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpress WPF能创建有着强大互动功能的XAML基础应用程序,这些应用程序专注于当代客户的需求和构建未来新一代支持触摸的解决方案。 无论是Office办公软件的衍伸产品,还是以数据为中心的商业智能产品,都能通过DevExpress WPF控件来实现。


    DevExpress技术交流群4:715863792      欢迎一起进群讨论

    更多DevExpress线上公开课、中文教程资讯请上中文网获取

  • 相关阅读:
    【原创】Zend Framework快速开发(二)使用命令完成项目
    分析CMMS系统笔记使用js控制快捷键
    学习笔记——php利用@来抑制错误
    WINDOWS + WAMP + Zend Framework 配置
    PHP的$_SERVER变量笔记
    【原创】Zend Framework快速开发(一)zend框架的配置和项目创建(原创)
    带符号的8位2进制数最小值为多少?
    动态规划笔记
    我一直在拖国家的后退
    手机客户端和服务器通信时如何安全高效的进行身份验证
  • 原文地址:https://www.cnblogs.com/AABBbaby/p/15102626.html
Copyright © 2011-2022 走看看