1

我不想在 wpf 中做这样的事情在此处输入图像描述

所以我试试这个xaml:

 <StackPanel HorizontalAlignment="Left">
        <ListView ItemsSource="{Binding Path=StateItems}">
            <ListView.ItemTemplate>
                <DataTemplate DataType="vm:StateItem">
                    <StackPanel Orientation="Horizontal">
                        <Image>
                            <Image.Style>
                                <Style>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Path=Active}" Value="True">
                                            <Setter Property="Image.Source" Value="{StaticResource Ellipse}" />
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding Path=Active}" Value="False">
                                            <Setter Property="Image.Source" Value="{StaticResource EllipseEmpty}" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Image.Style>
                        </Image>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackPanel>

这在 viewModel 中:

  public List<StateItem> StateItems
    {
        get
        {
            var items = new StateItem[m_InstallationSteps.Steps.Count];
            items[m_InstallationSteps.ActiveStepIndex].Active = true;
            return items.ToList();
        }
    } 
public class StateItem
{
    public bool Active { get; set; }
}

但它没有出现。如何让它出现?

编辑:在我看来绑定不起作用

EDIT2:尝试使用通知进行更改,但没有帮助

  public class StateItem : INotifyPropertyChanged
{
    private bool m_Active;

    public bool Active
    {
        get { return m_Active; }
        set
        {
            m_Active = value;
            OnPropertyChanged("Active");
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    [NotifyPropertyChangedInvocator]
    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    }
}
4

1 回答 1

0

我是傻瓜))问题是 items[m_InstallationSteps.ActiveStepIndex].Active = true;

它为空,但 wpf 没有引发异常。

于 2013-08-09T12:41:52.050 回答