ListView SelectedItem没有得到同步

时间:2016-08-26 10:19:00

标签: wpf listview mvvm

我有以下ListView并使用MVVM Light

    <ListView ItemsSource="{Binding Combinations, UpdateSourceTrigger=PropertyChanged}"
              SelectedItem="{Binding Combination, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
             Style="{StaticResource UserValueStyle}" SelectionMode="Single"
             IsSynchronizedWithCurrentItem="True"
             ScrollViewer.HorizontalScrollBarVisibility="Disabled">
      <ListView.ItemsPanel>
        <ItemsPanelTemplate>
          <WrapPanel Orientation="Horizontal" ScrollViewer.HorizontalScrollBarVisibility="Disabled" />
        </ItemsPanelTemplate>
      </ListView.ItemsPanel>
      <ListView.ItemTemplate>
        <DataTemplate>
          <Button Content="{Binding Text}" FontSize="20" Height="80" Width="100" FontWeight="Bold"
                  Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.OnUserValuePressed}" />
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>

财产:

public SapInspectionUserValue Combination
    {
      get
      {
        return _combination;
      }
      set
      {
        _combination = value;
        RaisePropertyChanged();
      }
    }

类属性:

  public class SapInspectionUserValue
  {
    public string Combination { get; set; }
    public string Value { get; set; }
    public string Text { get; set; }
  }

我的问题是,当我选择一个项目时(在我的情况下,按下按钮)SelectedItem没有同步,我不知道为什么。什么是错的?

0 个答案:

没有答案