【发布时间】:2021-05-21 12:53:32
【问题描述】:
- 应根据用户在文本框中输入的值突出显示整行。
- 如果列表视图的“地名”列与该值匹配。
我已经能够根据数据触发器中的硬编码值实现突出显示,如下所示:
<DataTrigger Binding="{Binding Name}" Value="Manali"> <!-- this value should be dynamic based on element -->
<Setter Property="Background" Value="Yellow" />
</DataTrigger>
你能指出我正确的方向吗,我可以绑定
Value的属性吗? 运行时数据触发?
<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>
代码隐藏:
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;
}
}
【问题讨论】:
标签: c# wpf xamarin.forms