在 C# WPF开发中颜色对话框控件(ColorDialog)用于对界面中的背景、文字…(拥有颜色属性的所有控件)设置颜色,例如设置标签控件的背景色。
颜色对话框的运行效果如下图所示:
标签背景色设置后如下:
xaml代码:
<Window x:Class="WpfApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp"
Icon="https://demosc.chinaz.net/Files/pic/iconsico/8254/e9.ico"
mc:Ignorable="d"
Title="TestImage" Height="600" Width="900" WindowStartupLocation="CenterScreen">
<Window.Resources>
<ResourceDictionary x:Uid="CommandDict">
<RoutedCommand x:Uid="SetBackGround" x:Key="SetBackGround"/>
</ResourceDictionary>
</Window.Resources>
<Window.CommandBindings>
<CommandBinding x:Uid="SetBackGroundParameter" Command="{StaticResource SetBackGround}" Executed="Pic_BackGround_Click" />
</Window.CommandBindings>
<Window.InputBindings>
<KeyBinding x:Uid="AddKeyBinding" Key="O" Modifiers="Ctrl+Shift" Command="{StaticResource SetBackGround}"/>
</Window.InputBindings>
<Grid>
<DockPanel x:Name="myDockPanel">
<Menu DockPanel.Dock=