<small id='95gq8'></small><noframes id='95gq8'>

        • <bdo id='95gq8'></bdo><ul id='95gq8'></ul>
        <tfoot id='95gq8'></tfoot>

        <legend id='95gq8'><style id='95gq8'><dir id='95gq8'><q id='95gq8'></q></dir></style></legend>
      1. <i id='95gq8'><tr id='95gq8'><dt id='95gq8'><q id='95gq8'><span id='95gq8'><b id='95gq8'><form id='95gq8'><ins id='95gq8'></ins><ul id='95gq8'></ul><sub id='95gq8'></sub></form><legend id='95gq8'></legend><bdo id='95gq8'><pre id='95gq8'><center id='95gq8'></center></pre></bdo></b><th id='95gq8'></th></span></q></dt></tr></i><div id='95gq8'><tfoot id='95gq8'></tfoot><dl id='95gq8'><fieldset id='95gq8'></fieldset></dl></div>
      2. 根据另一个列表框的选择填充 WPF 列表框

        时间:2023-10-07

          • <bdo id='9hWSH'></bdo><ul id='9hWSH'></ul>
              <legend id='9hWSH'><style id='9hWSH'><dir id='9hWSH'><q id='9hWSH'></q></dir></style></legend>

              <tfoot id='9hWSH'></tfoot>
              1. <small id='9hWSH'></small><noframes id='9hWSH'>

                <i id='9hWSH'><tr id='9hWSH'><dt id='9hWSH'><q id='9hWSH'><span id='9hWSH'><b id='9hWSH'><form id='9hWSH'><ins id='9hWSH'></ins><ul id='9hWSH'></ul><sub id='9hWSH'></sub></form><legend id='9hWSH'></legend><bdo id='9hWSH'><pre id='9hWSH'><center id='9hWSH'></center></pre></bdo></b><th id='9hWSH'></th></span></q></dt></tr></i><div id='9hWSH'><tfoot id='9hWSH'></tfoot><dl id='9hWSH'><fieldset id='9hWSH'></fieldset></dl></div>
                    <tbody id='9hWSH'></tbody>
                  本文介绍了根据另一个列表框的选择填充 WPF 列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个绑定到 observablecollection 的列表框.observable 集合包含一个对象列表,每个对象都有自己的 observablecollection.我想要的是单击第一个列表框中的一个项目,并将它的列表显示在第二个列表框中.我可以在纯 WPF 中执行此操作吗?

                  I have a listbox that is bound to an observablecollection. The observable collection contains a list of objects, each with it's own observablecollection. What i want is to click an item in the first listbox and have it's list of things displayed in the second listbox. Can I do this in pure WPF?

                  推荐答案

                  只需将第二个列表框的ItemsSource绑定到第一个列表框的SelectedItem即可.

                  Just bind the ItemsSource of the second listbox to the SelectedItem of the first list box.

                  这里有一些代码.

                  public partial class MainWindow : Window
                  {
                      public MainWindow()
                      {
                          TestItems = new ObservableCollection<Test>();
                          InitializeComponent();
                  
                          for (int i = 0; i < 5; i++)
                              TestItems.Add(InitTest(i));
                      }
                  
                      public ObservableCollection<Test> TestItems { get; set; }
                  
                      private Test InitTest(int index)
                      {
                          Test test = new Test();
                          test.Name  = "Test" + index.ToString();
                          test.Test2Items =  new ObservableCollection<Test2>();
                  
                          for (int i = 0; i <= index; i++)
                          {
                              Test2 test2 = new Test2();
                              test2.Label = test.Name + "_label" + i.ToString();
                              test.Test2Items.Add(test2);
                          }
                          return test;
                      }
                  }
                  
                  public class Test
                  {
                      public string Name { get; set; }
                      public ObservableCollection<Test2> Test2Items { get; set; }
                  
                      public override string ToString()
                      {
                          return Name;
                      }
                  }
                  
                  public class Test2
                  {
                      public string Label { get; set; }
                      public override string ToString()
                      {
                          return Label;
                      }
                  }
                  

                  Xaml

                   <Window x:Class="WpfApplication1.MainWindow"
                          x:Name="MyWindow"
                          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                          Title="WPF Example" Height="300" Width="400">
                      <Grid>
                          <Grid.ColumnDefinitions>
                              <ColumnDefinition Width="*" />
                              <ColumnDefinition Width="*" />
                          </Grid.ColumnDefinitions>
                          <ListBox x:Name="ListBox1" Grid.Column="0" ItemsSource="{Binding TestItems, ElementName=MyWindow}" />
                          <ListBox Grid.Column="1" ItemsSource="{Binding SelectedItem.Test2Items, ElementName=ListBox1}" />
                      </Grid>
                  </Window>
                  

                  这篇关于根据另一个列表框的选择填充 WPF 列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:直接上传新的 Ftp 列表框行 下一篇:文件名字符串转换器的文件路径不起作用

                  相关文章

                    <legend id='zZYFa'><style id='zZYFa'><dir id='zZYFa'><q id='zZYFa'></q></dir></style></legend>

                    <i id='zZYFa'><tr id='zZYFa'><dt id='zZYFa'><q id='zZYFa'><span id='zZYFa'><b id='zZYFa'><form id='zZYFa'><ins id='zZYFa'></ins><ul id='zZYFa'></ul><sub id='zZYFa'></sub></form><legend id='zZYFa'></legend><bdo id='zZYFa'><pre id='zZYFa'><center id='zZYFa'></center></pre></bdo></b><th id='zZYFa'></th></span></q></dt></tr></i><div id='zZYFa'><tfoot id='zZYFa'></tfoot><dl id='zZYFa'><fieldset id='zZYFa'></fieldset></dl></div>
                      • <bdo id='zZYFa'></bdo><ul id='zZYFa'></ul>

                      <small id='zZYFa'></small><noframes id='zZYFa'>

                      <tfoot id='zZYFa'></tfoot>