WPF - 单个项目选择,扩展器嵌套在列表视图中

时间:2015-04-01 04:45:08

标签: wpf xaml listview gridview expander

在我的.xaml文件中,我有一个包含exapnder的列表视图。问题是它不允许我一次选择一个项目。

       <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

我的意思是我想选择&#34;项目1&#34;当我想要的时候。同样,&#34;项目2&#34;如果我想。但是会发生的是,所有项目都会立即被选中。我是说,&#34;项目1&#34;,&#34;项目2&#34;和&#34;项目3&#34;当涉及到标题1.当然,&#34;项目1&#34; ,&#34;项目2&#34; ,&#34;项目3&#34;和&#34;项目4&#34;当谈到&#34; Header 2&#34;。无法选择单个项目。

你能告诉我哪里出错了,我应该设置哪些属性才能获得所需的功能?

1 个答案:

答案 0 :(得分: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;
}
相关问题