1
votes

I have a complex object bound to a DevExpress grid, with a custom EditTemplate

<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>

My complex object Value can be encrypted or not, so the object has a property IsEncrypted (which is Boolean). My first thought was to create a converter to decrypt value on display and encrypt it on save, and bind it only on another textbox which is shown only if the boolean is true.

However, making my encrypted textbox visiblity to collapsed doesn't prevents binding, and create some except preventing window to show up (I cannot modify the behavior of the crypting function because it's used many places in other applications and it has to throw exception)...

Because ConverterParameter cannot be bound, how can I achieve my goal ?

2
Would it be possible to create some kind of view model class and bind this class to your xaml? In the view model class you could have a "DisplayValue" property there which you could bind to. This property could check whether the raw value is encrypted or not and could (along with other properties) help you to create data with is easier to bind than your "raw" data. - Martin
How can I just forget this idea .. Thank you, I create a wrapper viewmodel around my complex object to handle this situation both ways ! - cdie
Ok, then I will create a short answer for this - Martin

2 Answers

1
votes

In order to avoid complex XAML markup which checks for complex conditions on raw data it is often better to create some kind of view model class and bind this class to the XAML.

In the view model class you could have a "DisplayValue" property which you could bind to. This property could check whether the raw value is encrypted or not and could (along with other properties) help you to create data with is easier to bind than your "raw" data.

By doing this, your have more like "1:1" (control to property) bindings from the view to the view model. The conversion from the raw data to the way it is displayed can then be done in the view model.

0
votes

You could create your own, custom MultiBinding. Bind that to the Value and IsEncrypted, and do your special handling there (i.e. ignore the Value if IsEncrypted is true).