DataTrigger doesn't enter to the Converter
this is the xaml:
<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="N开发者_JAVA技巧ame" />
<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>
and this is the codebehind of the 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";
}
}
I cannot tell what you are trying to update/modify with the trigger.
Perhaps you can provide more detail if the following does not help.
If you modify the DataTemplate as follows you will enter the Converter.
<ListView ItemsSource="{Binding Persons}">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource con}">
<Binding Path="Name" />
<Binding Path="Age" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I'll assume that you implemented your converter using IMultiValueConverter.
In my case I returned a concatenated string of name and age.
精彩评论