Revils
Revils

Reputation: 1508

DataTrigger C# in resourceDictionary

I have searched some topics on Stackoverflow, but none seem to work for me.

I set the DataGrid Columns based on columns in a resourceDictionary. (This dictionary consists of DataGridTemplateColumn's.) One of these columns contains binding to a Boolean value. however I do not want 'True' or 'False', I want to have '√' or ''.

This does not seem to work for me (DataTrigger for Textblock). It still keeps the 'True' or 'False'.

This is the textblock inside the template:

<TextBlock Text="{Binding booleanValue}" TextAlignment="Center">
    <TextBlock.Style>
        <Style TargetType="{x:Type TextBlock}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding booleanValue}" Value="True">
                    <Setter Property="Text" Value="√"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding booleanValue}" Value="False">
                    <Setter Property="Text" Value=""/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </TextBlock.Style>
</TextBlock>

What am I missing or should I change?

Upvotes: 1

Views: 632

Answers (1)

Heena
Heena

Reputation: 8634

Your DataTrigger is not change the value of the Text property because you set it inside the TextBlock declaration. So, once setted, it will never changed. To allow changing, you have to set the value inside the Style.

Upvotes: 2

Related Questions