![](/img/trans.png)
[英]Binding WPF Extended Toolkit ColorPicker SelectedColor Property to DependencyProperty
[英]WPF ColorPicker from wpf/xaml/toolkit binding to property error
我有一些关于colorpicker的代码:
<xctk:ColorPicker Grid.Row ="10" Grid.ColumnSpan="2" Margin="5, 5, 5, 5" Height="30" DisplayColorAndName="True"
SelectedColor="{Binding SelectedItem.TransparentColor, ElementName=ItemsListBox, Converter={StaticResource BrushColorConverter}, Mode=TwoWay}"/>
当绑定到ElementName = Window和Path = Background时,这些东西有效,但是当我创建具有System.Windows.Media.Color属性的对象时,它将显示
Value produced by BindingExpression is not valid for target property.; Value='<null>' BindingExpression:Path=SelectedItem.TransparentColor; DataItem='ListBox' (Name='ItemsListBox'); target element is 'ColorPicker' (Name=''); target property is 'SelectedColor' (type 'Color')
属性TransparentColor是新对象(new System.Windows.Media.Color())...我应该怎么做才能使其正常工作?
其他类似:
<TextBox Grid.Column="7" Text="{Binding SelectedItem.ForbiddenArea.Height, ElementName=ItemsListBox, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
作品...
修复起来很容易:首先,我从System.Windows.Media声明了可为空的Color
Color? TransparentColor { get; set; }
并在没有Converter的情况下绑定到此属性:
<xctk:ColorPicker Grid.Row ="12" Grid.ColumnSpan="2" Height="30" DisplayColorAndName="True"
SelectedColor="{Binding TransparentColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding ElementName=GlobalTransparencyFlag, Path=IsChecked}"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.