我有綁定到的DevExpress網格一個複雜的對象,與自定義EditTemplateWPF - 如何禁用基於對象屬性的綁定?
<ControlTemplate x:Key="EditLine">
<StackPanel VerticalAlignment="Center">
<TextBox Text="{Binding RowData.Row.Value}"
Margin="2"
Visibility="{Binding RowData.Row.ParamType, Converter={StaticResource ValueTypeToVisibilityConverter}, ConverterParameter='TextBox'}" />
<CheckBox Visibility="{Binding RowData.Row.ParamType, Converter={StaticResource ValueTypeToVisibilityConverter}, ConverterParameter='CheckBox'}"
IsChecked="{Binding RowData.Row.Value}"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</StackPanel>
</ControlTemplate>
我的複雜對象值可以被加密或沒有,所以對象具有屬性IsEncrypted(這是布爾值)。我的第一個想法是創建一個轉換器來解密顯示的值並在保存時對其進行加密,並僅在另一個僅在布爾值爲true時才顯示的文本框上進行綁定。
但是,使我的加密文本框visiblity摺疊不會阻止綁定,並創建一些除了防止窗口顯示(我不能修改加密函數的行爲,因爲它在其他應用程序中使用很多地方,它必須拋出異常)...
由於ConverterParameter無法綁定,我該如何實現我的目標?
是否有可能創建某種視圖模型類並將此類綁定到您的xaml?在視圖模型類中,您可以在其中綁定到「DisplayValue」屬性。該屬性可以檢查原始值是否被加密,並且可以(與其他屬性一起)幫助您創建數據,比「原始」數據更容易綁定。 – Martin
我怎麼才能忘記這個想法..謝謝,我創建了一個包裝我的複雜對象視圖模型來處理這種情況兩種方式! – cdie
好吧,然後我會爲這個 – Martin