DevExpress WPF入门级教程 – 如何使用调色板资源

本教程将为大家介绍如何自如何使用调色板资源,欢迎下载最新版体验~

您可以将每个调色板颜色用作颜色 (PaletteColorThemeKey) 或画笔 (PaletteBrushThemeKey)。

MainWindow.xaml

<ThemedWindow ...xmlns:dxi="http://schemas.devexpress.com/winfx/2008/xaml/core/internal"xmlns:dxt="http://schemas.devexpress.com/winfx/2008/xaml/themes"><Button Background="{dxi:ThemeResource {dxt:PaletteBrushThemeKey ResourceKey=Button.Background}}"BorderBrush="{dxi:ThemeResource {dxt:PaletteBrushThemeKey ResourceKey=Border}}"BorderThickness="1" /></ThemedWindow>

示例

下面的代码示例演示了如何将VS2017Blue主题的Border调色板资源绑定到自定义控件的BorderBrush属性:

CustomControls.cs

using System.Windows;using System.Windows.Controls;namespace WpfApp36 {public class CustomControl1 : Control {static CustomControl1() {DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1)));}public string Text {get { return (string)GetValue(TextProperty); }set { SetValue(TextProperty, value); }}public static readonly DependencyProperty TextProperty =DependencyProperty.Register("Text", typeof(string), typeof(CustomControl1), new PropertyMetadata(null));}}

MainWindow.xaml

<Windowxmlns:local="clr-namespace:WpfApp36"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"x:Class="WpfApp36.MainWindow"><Grid><Grid.RowDefinitions><RowDefinition/></Grid.RowDefinitions><local:CustomControl1 Grid.Row="0" Margin="5" Text="Custom control binding to a theme name"/></Grid></Window>CustomControl1_Resources.xaml<ResourceDictionary xmlns_x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:dxt="http://schemas.devexpress.com/winfx/2008/xaml/core/themekeys"xmlns:local="clr-namespace:WpfApp36"><Style TargetType="{x:Type local:CustomControl1}"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type local:CustomControl1}"><Border BorderBrush="{DynamicResource {dxt:PaletteBrushThemeKey ResourceKey=Border, ThemeName=VS2017Blue}}" BorderThickness="3"><TextBlock Foreground="Black" HorizontalAlignment="Center" Text="{TemplateBinding Text}" VerticalAlignment="Center"/></Border></ControlTemplate></Setter.Value></Setter></Style></ResourceDictionary>App.xaml<Application x_Class="WpfApp36.App"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"StartupUri="MainWindow.xaml"><Application.Resources><ResourceDictionary><ResourceDictionary.MergedDictionaries><ResourceDictionary Source="/WPFApp36;component/CustomControl1_Resources.xaml" /></ResourceDictionary.MergedDictionaries></ResourceDictionary></Application.Resources></Application>

添加 XPF.Core 和 VS2017Blue 主题引用来运行这个项目。

DevExpress WPF入门级教程 - 如何使用调色板资源
调色板颜色列表

此部分包含调色板颜色名称和值。

您可以在以下文件中找到主题资源键:

DevExpressControlsInstallationPathComponentsSourcesDevExpress.Xpf.ThemesTheme_NameCoreCore ThemesTheme_NamePalettes.xaml DevExpressControlsInstallationPathComponentsSourcesDevExpress.Xpf.ThemesTheme_NameCoreCore ThemesTheme_NamePalettes_Base.xaml

DevExpress WPF | 下载试用

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


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

DevExpress 8月公开课火热 名中
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年7月15日
下一篇 2021年7月15日

相关推荐

发表回复

登录后才能评论