Skip to content

Instantly share code, notes, and snippets.

@HakanL
Last active May 3, 2022 23:26
Show Gist options
  • Save HakanL/c845a3d8921c76f884c8703a97c385ee to your computer and use it in GitHub Desktop.
Save HakanL/c845a3d8921c76f884c8703a97c385ee to your computer and use it in GitHub Desktop.
XAML UserControl showing ListView with DataTrigger for boolean replacement
<UserControl x:Class="TestApplication.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<ListView>
<ListView.View>
<GridView>
<GridViewColumn Width="50" Header="Rec. No" DisplayMemberBinding="{Binding RecordNo}" />
<GridViewColumn Width="100" Header="Value" DisplayMemberBinding="{Binding Value, StringFormat=\{0:N0\} dB}" />
<GridViewColumn Width="120" Header="BoolTest1">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Text" Value="No" />
<Style.Triggers>
<DataTrigger Binding="{Binding BoolProperty1}" Value="True">
<Setter Property="Text" Value="Yes" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="110" Header="BoolTest2">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Text" Value="No" />
<Style.Triggers>
<DataTrigger Binding="{Binding BoolProperty2}" Value="True">
<Setter Property="Text" Value="Yes" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</UserControl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment