WPF的ColorPicker从WPF / XAML /工具绑定属性错误 [英] WPF ColorPicker from wpf/xaml/toolkit binding to property error

查看:179
本文介绍了WPF的ColorPicker从WPF / XAML /工具绑定属性错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些code与颜色拾取:

I've got some code with 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 =窗口和路径=背景这东西的作品,但是当我创建财产System.Windows.Media.Color对象,它显示了

This stuff works when is Binded to ElementName=Window and Path=Background, but when I'm creating object with property System.Windows.Media.Color, it shows

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是新对象(新System.Windows.Media.Color())...
我应该怎么做,使之正常工作?

Property TransparentColor is new object ( new System.Windows.Media.Color() )... What should I do to make it working?

其他的事情,如:

<TextBox Grid.Column="7" Text="{Binding SelectedItem.ForbiddenArea.Height, ElementName=ItemsListBox, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

作品...

推荐答案

这是很容易解决:
首先,我已经声明为空的颜色从System.Windows.Media

It was easy to fix: Firstly I've declared nullable Color from System.Windows.Media

Color? TransparentColor { get; set; }

和绑定到该属性没有转换器:

And Binding to this property without 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}"/>

这篇关于WPF的ColorPicker从WPF / XAML /工具绑定属性错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆