Home > OS >  data Triggers in dxg:GridColumn DevExpress
data Triggers in dxg:GridColumn DevExpress

Time:12-08

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>

CodePudding user response:

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>

CodePudding user response:

I solved this problem without DevExpress like this

                        <dxg:GridColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock  TextAlignment="Center">
                                    <TextBlock.Style>
                                        <Style TargetType="{x:Type TextBlock}">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding Path=Data.IsLocked}" Value="True">
                                                    <Setter Property="Text" Value="{x:Static localization:Resources.Locked}"/>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding Path=Data.IsLocked}" Value="False">
                                                    <Setter Property="Text" Value="{x:Static localization:Resources.UnLocked}"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </TextBlock.Style>
                                </TextBlock>
                            </DataTemplate>
                        </dxg:GridColumn.CellTemplate>
                    </dxg:GridColumn>
  • Related