2013-01-24 50 views
0

我有一些代码,使颜色拾取:WPF颜色拾取从WPF/XAML /工具结合属性错误

<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米创建对象,它显示

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())... 我应该怎么做,使之加工?

其他的东西,如:

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

作品...

+1

只是为了检查:有一个System.Windows.Media.Color和一个System.Drawing.Color。 SelectedColor不是一个System.Drawing.Color? – Nzc

+0

不,这是S.W.M.C ... –

回答

0

这是很容易解决:从System.Windows.Media

Color? TransparentColor { get; set; } 

首先,我已经声明为空的颜色并绑定到此属性无转换器:

<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}"/>