Nic*_*cki 6 wpf xaml toolkit colors picker
我已经在谷歌上找了几个小时我的问题的解决方案,但是找不到太多信息.
我正在使用WPF Toolkit v2.2.1.
我的WPF应用程序中有一个Color Picker控件,需要自定义样式.我正在编辑App.xaml中颜色选择器的控件模板以应用于所有颜色选择器.
一旦我选择使用模板,所有可用的颜色都会从拾色器消失.我试图从代码中分配新的可用颜色但没有成功.
颜色的集合在那里,它们似乎没有显示.
这就是我在mainwindow.xaml中定义CP的方式
<xctk:ColorPicker x:Name="cpRing" SelectedColorChanged="cpRing_Changed" HorizontalAlignment="Left" Margin="238,5,0,0" VerticalAlignment="Top" Height="20" Width="39" Foreground="Black"/>
Run Code Online (Sandbox Code Playgroud)
不幸的是,控件模板太大而无法粘贴到此处.但是,通过将CP添加到wpf窗口并在设计视图中右键单击它并选择"编辑模板",可以轻松地重现这一点.一旦应用,颜色将消失,不会改变任何东西.
在编辑控件模板时,是否有人知道如何使用可显示的颜色?
最好的祝福
是的,它的风格有些不对劲.但如果你仔细观察它的风格,你会发现问题所在:
搜索关键字StandardColors或AvailableColors在xaml中,这是StandardColors模板:
<ListBox x:Name="PART_StandardColors" Grid.Row="1">
<ListBox.Style>
<Style TargetType="{x:Type ListBox}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="ItemsPanel">
....
</ListBox.Style>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
你可以看到列表框没有设置itemsource,所以你可以自己添加:
<ListBox x:Name="PART_StandardColors" ItemsSource="{TemplateBinding StandardColors}" Grid.Row="1">
Run Code Online (Sandbox Code Playgroud)
编辑列表框AvailableColors:
<ListBox x:Name="PART_AvailableColors" ItemsSource="{TemplateBinding AvailableColors}" Grid.Row="1">
Run Code Online (Sandbox Code Playgroud)
现在它有效.