WPF コントロールにいくつかの画像 (位置) があります。ListView
各画像は、そのコントロールの下にある項目に関連付けられています。ユーザーが位置をクリックすると、対応する位置ListViewItem
が選択されます (したがって、強調表示されます) ListView
。同様に、ユーザーが をクリックするListViewItem
と、対応する位置が選択されるようにします。
どちらか一方の動作を行うことはできますが、両方を一緒に機能させることはできないようです。
位置が選択されたときにプロパティを「true」にStyle
設定する があります。IsSelected
<Style x:Key="PositionItem" TargetType="ListViewItem">
<Setter Property="IsSelected" Value="False" />
<Style.Triggers>
<DataTrigger Value="True">
<DataTrigger.Binding>
<MultiBinding Converter="{StaticResource IsCurrentPositionConverter}">
<Binding RelativeSource="{RelativeSource Self}" Path="DataContext" />
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.CurrentBackplane.CurrentCard.CurrentPosition" />
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="IsSelected" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
私のListView
では、次のハンドラーを設定しましたSelectionChanged
。
private void Positions_SelectionChanged(object sender, SelectionChangedEventArgs e) {
var listView = sender as ListView;
if (listView == null) return;
var currentPos = listView.SelectedItem as IGraphicPositionViewModel;
if (currentPos == null) return;
if (currentPos != _ViewModel.CurrentBackplane.CurrentCard.CurrentPosition)
_ViewModel.CurrentBackplane.CurrentCard.CurrentPosition = currentPos;
}
問題は、 のIsSelected
プロパティがのプロパティListViewItem
とうまく相関していないように見えることです。SelectedItem
ListView
これらのプロパティを同期するために使用できる他のプロパティまたはイベントはありますか?