2010-10-13 4 views
1

это XAML:DataTrigger не входит в конвертер

<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"; 
    } 

}

ответ

0

я не могу сообщите, что вы пытаетесь обновить/изменить с помощью триггера.
Возможно, вы можете предоставить более подробную информацию, если следующее не поможет.

Если вы измените DataTemplate следующим образом, вы введете Конвертер.

<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> 

Я предполагаю, что вы внедрили свой конвертер с помощью IMultiValueConverter.
В моем случае я вернул конкатенированную строку имени и возраста.