簡體   English   中英

WPF ColorPicker從WPF / XAML /工具包綁定到屬性錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM