这是xml:
<Window x:Class="WpfApplication4.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="clr-namespace:WpfApplication4" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1"
Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.Resources>
<local:MultiConverter x:Key="con" />
</Grid.Resources>
<ListView ItemsSource="{Binding Persons}">
<ListView.ItemTemplate>
<DataTemplate>
<DataTemplate.Triggers>
<DataTrigger Value="True">
<DataTrigger.Binding>
<MultiBinding Converter="{StaticResource con}">
<Binding Path="Name" />
<Binding Path="Age" />
</MultiBinding>
</DataTrigger.Binding>
</DataTrigger>
</DataTemplate.Triggers>
<TextBlock Text="{Binding Name}">
</TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Button Grid.Row="1" Click="Button_Click" ></Button>
</Grid>
这是window1的代码隐藏:
public partial class Window1 : Window {
public List<Person> Persons { get; set; }
public Window1() {
Persons = new List<Person>()
{
new Person(){Name="Keli",Age=1},
new Person(){Name="Keli",Age=2},
new Person(){Name="Tom",Age=3},
new Person(){Name="Keli",Age=4},
new Person(){Name="Keli",Age=5},
};
InitializeComponent();
DataContext = this;
}
private void Button_Click(object sender, RoutedEventArgs e) {
Persons[0].Name = "Tom";
}
}