Search code examples
c#wpfuwpdevexpress-wpf

data Triggers in dxg:GridColumn DevExpress


hi guys i hope you doing well. i'm using devExpress with wpf and i stuck in this: i have dxg:GridColumn who receive a boolean and i wanna change the content of this cell deppends on this boolean as you see bellow if True show => "Locked" if False show => "UnLocked"

<dxg:GridColumn IsSmart="True" FieldName="IsLocked" Header="{x:Static localization:Resources.Property_IsLocked}">
                        <dxg:GridColumn.EditSettings>
                            <dxe:TextEditSettings HorizontalContentAlignment="Center" Style="{DynamicResource trythisone}">
                            </dxe:TextEditSettings>
                        </dxg:GridColumn.EditSettings>
</dxg:GridColumn>

and i set the style as this

<Style x:Key="trythisone" TargetType="{x:Type dxe:TextEditSettings}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=Text}" Value="True">
                        <Setter Property="TextBlock.Text" Value="okokok"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=Content}" Value="False">
                        <Setter Property="TextBlock.Text" Value="ssssssssssssss"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

Solution

  • I think you can use the DisplayTextConverter:

    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
    ...
    <dxg:GridColumn IsSmart="True" FieldName="IsLocked" Header="{x:Static localization:Resources.Property_IsLocked}">
        <dxg:GridColumn.EditSettings>
            <dxe:TextEditSettings DisplayTextConverter="{dxmvvm:BooleanToObjectConverter TrueValue=Locked, FalseValue=UnLocked}" />
        </dxg:GridColumn.EditSettings>
    </dxg:GridColumn>