I have looked for a solution to my problem on Google for hours, but there isnt much information to find.
我已经在谷歌上找了几个小时我的问题的解决方案,但是找不到太多信息。
I am using WPF Toolkit v2.2.1.
我正在使用WPF Toolkit v2.2.1。
I have a Color Picker control in my WPF application, which needs to be custom styled. I am editing the control template of the Color Picker in App.xaml to apply to all color pickers.
我的WPF应用程序中有一个Color Picker控件,需要自定义样式。我正在编辑App.xaml中拾色器的控件模板以应用于所有颜色选择器。
As soon as I choose to use the template all available colors dissapear from the Color Picker. I have tried to assign new available colors from code with no success.
一旦我选择使用模板,所有可用颜色都会从拾色器中消失。我试图从代码中分配新的可用颜色但没有成功。
The Collection of colors are there, they are just not displayed it seems.
颜色的集合在那里,它们似乎没有显示。
This is how the CP is defines in my mainwindow.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"/>
The control template is too large to paste here unfortunately. But this should be easily reproduceable by adding a CP to a wpf window and rightclick it in designview and choose Edit Template. As soon as it is applied the colors will dissapear, without changing anything.
不幸的是,控件模板太大而无法粘贴到此处。但是,通过将CP添加到wpf窗口并在设计视图中右键单击它并选择“编辑模板”,可以轻松地重现这一点。一旦应用,颜色将消失,不会改变任何东西。
Does anybody know what to do to get the avaiable colors to display when editing the control template?
在编辑控件模板时,是否有人知道如何使用可显示的颜色?
Best regards
最好的祝福
1 个解决方案
#1
5
yep, it has something wrong with it's style. But if you observe it's style carefully you will find out the problem:
是的,它的风格有问题。但如果你仔细观察它的风格,你会发现问题所在:
search key word StandardColors
or AvailableColors
in xaml, here is StandardColors
's template:
在xaml中搜索关键字StandardColors或AvailableColors,这里是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>
you can see the listbox has not set itemsource, so you can add it by yourself:
你可以看到列表框没有设置itemsource,所以你可以自己添加:
<ListBox x:Name="PART_StandardColors" ItemsSource="{TemplateBinding StandardColors}" Grid.Row="1">
edit listbox of AvailableColors
:
编辑AvailableColors的列表框:
<ListBox x:Name="PART_AvailableColors" ItemsSource="{TemplateBinding AvailableColors}" Grid.Row="1">
now it works.
现在它有效。
#1
5
yep, it has something wrong with it's style. But if you observe it's style carefully you will find out the problem:
是的,它的风格有问题。但如果你仔细观察它的风格,你会发现问题所在:
search key word StandardColors
or AvailableColors
in xaml, here is StandardColors
's template:
在xaml中搜索关键字StandardColors或AvailableColors,这里是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>
you can see the listbox has not set itemsource, so you can add it by yourself:
你可以看到列表框没有设置itemsource,所以你可以自己添加:
<ListBox x:Name="PART_StandardColors" ItemsSource="{TemplateBinding StandardColors}" Grid.Row="1">
edit listbox of AvailableColors
:
编辑AvailableColors的列表框:
<ListBox x:Name="PART_AvailableColors" ItemsSource="{TemplateBinding AvailableColors}" Grid.Row="1">
now it works.
现在它有效。