2012-11-26 120 views
0

我在ListBox中遇到擴展選擇的問題。比方說,我有一個ListBox有10個項目,我使用Shift按鈕選擇前5個。該事件被激發5項。之後,我想從這5箇中選擇3個項目,再次按下Shift按鈕,但SelectionChanged事件未被解僱。當我選擇其中5個之前選擇的項目中的3個時,我如何對第二個項目選擇做出反應?WPF列表框選擇

+0

您可以通過張貼代碼開始,這樣我們可以檢查它是什麼,你在做錯誤的代碼隱藏.. – MethodMan

+0

嗯。目前,我創建了一個簡單的項目,只有一個列表框和SelectedChanged事件處理程序(因此它簡化了我的問題),但它可以像我期望的那樣工作。看起來像我的對象模型和綁定的問題。 – Blablablaster

+0

這就是爲什麼我發佈綁定的例子我懷疑這是你當前的問題.. – MethodMan

回答

0

您可以顯示XAML代碼,以及我想看到你的結合看起來像 它應該看起來是這樣的..但除非我看到你的代碼

在命令結合我不能肯定你已經使用結合其具有相對源綁定...

考慮作出這些改變使用列表框Ancestortype

2)當結合使用路徑= DataContext.Sele結合

1) ctionChangedCommand否則它會將列表框作爲datacontext。

<catel:EventToCommand Command="{Binding Path=DataContext.SelectionChangedCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" DisableAssociatedObjectOnCannotExecute="False" PassEventArgsToCommand="True" /> 

這裏的XAML會是什麼樣一個例子ListBoxItem的模板

<Grid> 
<StackPanel Orientation="Horizontal"> 
    <Label Width="180">Field1</Label> 
    <ListBox Height="200" 
      IsSynchronizedWithCurrentItem="True" 
      ItemsSource="{Binding List1, Mode=OneWay}" 
      Name="listBox1" 
      SelectionMode="Single" 
      Width="300"> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <StackPanel Orientation="Horizontal" Width="290"> 
        <TextBlock Width="90" Text="{Binding}"></TextBlock> 
         <ComboBox Width="180" ItemsSource="{Binding DataContext.List2, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" DisplayMemberPath="Field1"> 
          <i:Interaction.Triggers> 
           <i:EventTrigger EventName="SelectionChanged"> 
             <catel:EventToCommand Command="{Binding Path=DataContext.SelectionChangedCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" DisableAssociatedObjectOnCannotExecute="False" PassEventArgsToCommand="True" /> 
           </i:EventTrigger> 
          </i:Interaction.Triggers> 
         </ComboBox> 
        </StackPanel> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
</StackPanel>