2010-02-17 37 views
1

在我使用DataTemplate機制的應用程序中,我插入ListBox項目的另一個列表框。但是,它可能選擇在父列表框中一個ListBoxItem的時候,焦點可能放在另一個父ListBoxItem中的孩子(見圖片)WPF:如果用戶點擊子列表框,如何選擇父列表框

Pic http://i053.radikal.ru/1002/fc/3e68c57e3488.png

怎麼做:如果(在重點子列表框中的一個從一個項目他們選擇),然後父列表文件被選中?使用結合或模板

<DataTemplate x:Key="NotesListBoxDataTemplate" DataType="Note"> 
    <StackPanel Orientation="Vertical"> 

     <StackPanel Orientation="Horizontal"> 
      <TextBox Text="{Binding Path=Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox> 
      <my:DatePicker Height="25" Name="datePicker1" Width="115" xmlns:my="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit" 
          SelectedDate="{Binding LastEdit, 
                Mode = TwoWay}" /> 
     </StackPanel> 
     <TextBox Text="{Binding Path=Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox> 

     <StackPanel Orientation="Horizontal"> 
      <ListBox Name="ImagesListBox" SelectedIndex="{Binding Mode=OneWayToSource, Source={StaticResource progParameters}, Path=SelectedImage, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding Path=Images}" ItemTemplate="{StaticResource NotesListBoxImagesTemplate}" Style="{StaticResource HorizontalListBox}"> 
      </ListBox> 
      <StackPanel Orientation="Vertical"> 
       <Button Name="AddImageButon" Content="+" Click="AddImageButon_Click"></Button> 
       <Button Name="RemoveImageButon" Content="-" Click="RemoveImageButon_Click"></Button> 
      </StackPanel> 

     </StackPanel> 

    </StackPanel> 
</DataTemplate> 

回答

3

在父ListBox集屬性IsSynchronizedWithCurrentItemtrue,然後在內部ListBox ES的SelectedItem屬性設置爲​​。

考慮使用Converter來幫助您獲取無法通過xaml訪問的特定數據,或者需要執行一些計算。

希望這會有所幫助。