- Entire row should be highlighted based on the user entered value in textbox.
- If the Place Name column of List View matches that value.
I've been able to achieve highlighting based on hard coded value in data trigger as below:
<DataTrigger Binding="{Binding Name}" Value="Manali"> <!-- this value should be dynamic based on element -->
<Setter Property="Background" Value="Yellow" />
</DataTrigger>
Could you point me in right direction, Can I bind
Value
property of Data Trigger at runtime?
<Grid>
<Grid.Row>1</Grid.Row>
<Grid.Column>1</Grid.Column>
<StackPanel VerticalAlignment="Stretch">
<Label Content="Highlight word" />
<TextBox
x:Name="HighlightTextBox"
Margin="0,0,0,20"
Text="-TODO- Highlight Place Name column, based on entered value in this text box" />
<ListView x:Name="AbListView" GridViewColumnHeader.Click="AbListView_OnClick">
<ListView.Resources>
<Style TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding Name}" Value="Manali">
<Setter Property="Background" Value="Yellow" />
</DataTrigger>
</Style.Triggers>
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn
Width="Auto"
DisplayMemberBinding="{Binding Path=Name}"
Header="Place Name" />
<GridViewColumn
Width="500"
DisplayMemberBinding="{Binding Path=State}"
Header="State" />
</GridView>
</ListView.View>
</ListView>
<Button
x:Name="ApplyLabels"
Margin="15,15,15,15"
Click="ApplyLabels_OnClick">
Apply Labels
</Button>
</StackPanel>
</Grid>
Code Behind:
public partial class MainWindow : Window
{
public ObservableCollection<TouristPlace> TouristPlacces =>
new ObservableCollection<TouristPlace>(new List<TouristPlace>()
{
new TouristPlace("Manali", "KA", 51),
new TouristPlace("Coorg", "KA", 10),
new TouristPlace("Taj Mahal", "UP", 100),
new TouristPlace("Jagannath Temple", "OR", 90),
});
public MainWindow()
{
InitializeComponent();
AbListView.ItemsSource = TouristPlacces;
}
}