Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF-知道为什么datatrigger不开火吗?_Wpf_Styles_Datatemplate - Fatal编程技术网

WPF-知道为什么datatrigger不开火吗?

WPF-知道为什么datatrigger不开火吗?,wpf,styles,datatemplate,Wpf,Styles,Datatemplate,我的列表框定义如下。“Properties”是一个BindingList,我正在更改其中一个项目,但图像样式没有更新。你知道我可能遗漏了什么吗 <ListBox x:Name="lstProperties" Margin="0,0,5,0" ItemsSource="{Binding Properties}" SelectedItem=

我的列表框定义如下。“Properties”是一个BindingList,我正在更改其中一个项目,但图像样式没有更新。你知道我可能遗漏了什么吗

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

使您的模型实现INotifyPropertyChanged。
我包含了一些示例代码:

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