编辑:我实际上设法解决了问题,我正在执行Binding Value.Color
而不是之前设置的Binding Color
。无论如何,谢谢你的帮助!
我正在制作一个在xaml中具有xctk:ColorPicker的GUI:
<GridViewColumn.CellTemplate>
<DataTemplate>
<xctk:ColorPicker SelectedColor="{Binding Value.Color}" Width="40"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
目前,选择器的默认颜色是蓝色,我想将其更改为黑色。我该如何做到这一点?
答案 0 :(得分:1)
颜色选择器显示绑定属性值
的默认颜色所以在这种情况下,如果你的属性Value.Color返回蓝色,那么它将是蓝色
因此,通过将属性颜色更改为黑色会将其更改为黑色
但是如果您不想更改属性值,则可以使用默认值为black的占位符属性,并在更改时更新源
占位符方法的示例
<Grid Background="{Binding Value}">
<xctk:ColorPicker SelectedColor="{Binding PlaceHolder}" Width="40" VerticalAlignment="Center"/>
</Grid>
查看模型
bool isDefault = true;
public Color PlaceHolder
{
get
{
if (isDefault)
return Colors.Black;
return Value.Color;
}
set
{
Value.Color = value;
isDefault = false;
}
}
public SolidColorBrush Value { get; set; }
在上面的示例中,我假设类型SolidColorBrush
的值,并将其初始化为Value = new SolidColorBrush(Colors.Green);
答案 1 :(得分:0)
如果您使用的是.NET 4,则可以通过简单地定义几个Background
来更改GridView
中所选行的Resource
颜色...只需添加这些是GridView.Resources
集合:
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Blue" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Blue" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="Black" />