2010-07-01 2 views
0

Ma liste est définie ci-dessous. "Properties" est une BindingList dont je modifie l'un des éléments mais le style Image n'est pas mis à jour. Des idées de ce que je pourrais manquer?WPF - Des idées pour lesquelles le datatrigger ne se déclenche pas?

  <ListBox x:Name="lstProperties" 
        Margin="0,0,5,0" 
        ItemsSource="{Binding Properties}" 
        SelectedItem="{Binding CurrentProperty}"> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <Grid> 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition Width="16"/> 
           <ColumnDefinition/> 
          </Grid.ColumnDefinitions> 
          <Image> 
           <Image.Style> 
            <Style TargetType="{x:Type Image}"> 
             <Setter Property="Source" Value="Images/HouseRed_16.png"/> 
             <Style.Triggers> 
              <DataTrigger Binding="{Binding SuitableApplicationCount, Converter={StaticResource greaterThanConverter}, ConverterParameter=0}" Value="True"> 
               <Setter Property="Source" Value="Images/HouseYellow_16.png"/> 
              </DataTrigger> 
              <DataTrigger Binding="{Binding InterestedApplicationCount, Converter={StaticResource greaterThanConverter}, ConverterParameter=0}" Value="True"> 
               <Setter Property="Source" Value="Images/HouseAmber_16.png"/> 
              </DataTrigger> 
              <DataTrigger Binding="{Binding MatchedApplicationId, Converter={StaticResource isNullOrEmptyConverter}}" Value="False"> 
               <Setter Property="Source" Value="Images/HouseGreen_16.png"/> 
              </DataTrigger> 
             </Style.Triggers> 
            </Style> 
           </Image.Style> 
          </Image> 
          <TextBlock Grid.Column="1" VerticalAlignment="Center"> 
           <TextBlock.Text> 
            <MultiBinding StringFormat="{}Id: {0}, Plot: {1}"> 
             <Binding Path="Id" FallbackValue="" /> 
             <Binding Path="Plot" FallbackValue=""/> 
            </MultiBinding> 
           </TextBlock.Text> 
          </TextBlock> 
         </Grid> 
        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 

Répondre

0

Créez votre modèle d'outil INotifyPropertyChanged.
J'ai inclus un exemple de code:

public class MyModel : ViewModelBase 
{ 
    private int _suitableApplicationCount; 
    public int SuitableApplicationCount 
    { 
    get { return _suitableApplicationCount; } 
    set 
    { 
     _suitableApplicationCount = value; 
     OnPropertyChanged("SuitableApplicationCount"); 
    } 
    } 

    public int _interestedApplicationCount; 
    public int InterestedApplicationCount 
    { 
    get { return _interestedApplicationCount; } 
    set 
    { 
     _interestedApplicationCount = value; 
     OnPropertyChanged("InterestedApplicationCount"); 
    } 
    } 

    public int? _matchedApplicationId; 
    public int? MatchedApplicationId 
    { 
    get { return _matchedApplicationId; } 
    set 
    { 
     _matchedApplicationId = value; 
     OnPropertyChanged("MatchedApplicationId"); 
    } 
    } 
} 

public abstract class ViewModelBase : INotifyPropertyChanged 
{ 
    public event PropertyChangedEventHandler PropertyChanged; 

    protected void OnPropertyChanged(string propertyName) 
    { 
    PropertyChangedEventHandler handler = PropertyChanged; 

    if (handler != null) 
    { 
     handler(this, new PropertyChangedEventArgs(propertyName)); 
    } 
    } 
} 
Questions connexes