2011-04-21 19 views
2

リストビュー内で複数のアイテムを選択できます。しかし、1つをクリックすると、青色に変わります。それは正常なので、それは選択されていることを示しています。しかし、同じアイテムをもう一度クリックすると、選択が解除されません。だから私の選択を変更することはできません。この愚かな小さな問題を解決する方法を知っている誰か?リストビュー内の選択されたアイテムは選択解除されません

編集:これは私のリストビューです:

<ListView Height="155" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Visible" SelectedItem="{Binding Path=SelectedQuestionDropList, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" dd:DragDrop.IsDragSource="True" 
    dd:DragDrop.IsDropTarget="True" SelectionMode="Multiple" Margin="0,0,542,436" Background="#CDC5CBC5" 
       dd:DragDrop.DropHandler="{Binding}" Name="DropListView" ItemsSource="{Binding Path=SelectedExaminationQuestions,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" SelectionChanged="ListView_SelectionChanged_1" VerticalAlignment="Bottom"> 
      <ListView.View> 
       <GridView> 
        <GridView.Columns> 
         <GridViewColumn Header="Verkorte naam" Width="Auto" DisplayMemberBinding="{Binding Path=ShortName}" /> 
         <GridViewColumn Header="Omschrijving" Width="Auto" DisplayMemberBinding="{Binding Path=Description}" /> 
         <GridViewColumn Header="Type" Width="Auto" DisplayMemberBinding="{Binding Path=Type}" /> 

        </GridView.Columns> 
       </GridView> 
      </ListView.View> 
     </ListView> 
+0

OnSelectionChangedを選択した場合、コードビハインドで作業することができますが、それは私には奇妙なものです。私は、より良い方法、ただのプロパティなどがあることを願っています。 – Ruben

答えて

3

あなたは、WPFの振る舞いを記述することができます。以下のような何か:

public class ListViewBehaviour 
{ 
    /// <summary> 
    /// Enfoca automaticament el item sel·leccionat 
    /// </summary> 
    public static readonly DependencyProperty AutoUnselectItemProperty = 
     DependencyProperty.RegisterAttached(
      "AutoUnselect", 
      typeof(bool), 
      typeof(ListViewBehaviour), 
      new UIPropertyMetadata(false, OnAutoUnselectItemChanged)); 

    public static bool GetAutoUnselectItem(ListView listBox) 
    { 
     return (bool)listBox.GetValue(AutoUnselectItemProperty); 
    } 

    public static void SetAutoUnselectItem(ListView listBox, bool value) 
    { 
     listBox.SetValue(AutoUnselectItemProperty, value); 
    } 

    private static void OnAutoUnselectItemChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) 
    { 
     var listView = source as ListView; 
     if (listView == null) 
      return; 

     if (e.NewValue is bool == false) 
      listView.SelectionChanged -= OnSelectionChanged; 
     else 
      listView.SelectionChanged += OnSelectionChanged; 
    } 

    private static void OnSelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
     // TODO write custom selection behaviour 
    } 
} 

そして、リストビューにそれを適用する:

<ListView bb:ListViewBehaviour.AutoUnselect="True"> 
    ... 
</ListView> 
5

私は同様の問題に直面していたし、左クリック、常に項目を選択するにはに指摘している間、あなたはCtrlキーを使用することができ、ことを見出しました+左クリックすると、リストビューでの選択が切り替わります。これがデフォルト動作です。

関連する問題