2015-04-01 45 views
0

在我的.xaml文件中,我有一個包含exapnder的listview。問題是它不允許我一次選擇一個單一項目。WPF - 用擴展器嵌套在列表視圖中的單個項目選擇

 <ListView ....> 
      <GridView ....> 
        <Expander ...> 
         <stackPanel ...> 
          ....... 
         </stackpanel> 
        </Expander> 
      </GridView> 
     </ListView> 



     Header 1 
       - Item 1 
       - Item 2 
       - Item 3 
     Header 2 
       - Item 1 
       - Item 2 
       - Item 3 
       - Items 4 

我的意思是我想要選擇「項目1」時,我想。同樣,如果我想要,「項目2」。但是會發生的是所有的項目都是一次選擇的。我的意思是,當涉及到標題1時,「項目1」,「項目2」和「項目3」。當然,當它是「項目1」,「項目2」,「項目3」和「項目4」時來到「標題2」。沒有單個項目選擇是可能的。

你能告訴我哪裏出了問題,我應該設置哪些屬性以獲得所需的功能?

回答

0

嘗試WPF:

<Window x:Class="WpfApplication1.MainWindow" 
     x:Name="thisForm" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <ListView x:Name="f_List"> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
     <Expander Header="{Binding Path=Key}"> 
      <ListView ItemsSource="{Binding Path=Value}"> 
      </ListView> 
     </Expander> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
    </ListView> 
</Window> 

和C#代碼:

public MainWindow() 
{ 
    InitializeComponent(); 
    Dictionary<string, List<string>> twoLists = new Dictionary<string, List<string>>(); 
    twoLists.Add("1 List", new List<string>(new string[] { "1.1", "1.2", "1.3", "1.4" })); 
    twoLists.Add("2 List", new List<string>(new string[] { "2.1", "2.2", "2.3", "2.4" })); 
    twoLists.Add("3 List", new List<string>(new string[] { "3.1", "3.2", "3.3", "3.4" })); 
    twoLists.Add("4 List", new List<string>(new string[] { "4.1", "4.2", "4.3", "4.4" })); 
    f_List.ItemsSource = twoLists; 
} 
+0

太感謝你了!有用 :) – 2015-04-01 08:08:27

相關問題