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

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

      <tfoot id='LVna4'></tfoot>
        • <bdo id='LVna4'></bdo><ul id='LVna4'></ul>
      1. WPF 中的多列列表框

        时间:2023-10-08
        <legend id='7nd85'><style id='7nd85'><dir id='7nd85'><q id='7nd85'></q></dir></style></legend>

          <small id='7nd85'></small><noframes id='7nd85'>

              <tbody id='7nd85'></tbody>

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

                  本文介绍了WPF 中的多列列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有 3 个 TextBoxes 和 1 个 Button 并且想将每个 TextBoxes 数据输入到 ListBox 在单独的列中.

                  I have 3 TextBoxes and 1 Button and want to enter each of the the TextBoxes data into a ListBox in separate columns.

                  我知道如何将数据输入一列:

                  I know how to enter data into one column:

                  listbox1.Items.Add(TextBox1.text);
                  

                  但是如何将数据输入到多个列中?

                  but how can I enter the data into multiple columns?

                  我正在使用 .NET WPF.我想使用 ListBoxListView.

                  I am using .NET WPF. I want to use a ListBox or a ListView.

                  我的窗口

                  推荐答案

                  Ray 正确指出,ListView 会做工作.但是,如果您坚持使用和/或想要使用 ListBox,您也可以使用带有 Grid 的 ItemTemplate 并设置 Grid.IsSharedSizeScope 属性.例如:

                  As Ray correctly points out, ListView will do the job. However if you're stuck with and/or want to use ListBox, you can also use an ItemTemplate with Grid and set the Grid.IsSharedSizeScope property on the ListBox itself. For example:

                  <ListBox ItemsSource="{Binding DataSource}" Grid.IsSharedSizeScope="True">
                      <ListBox.ItemTemplate>
                          <DataTemplate>
                              <Grid>
                                  <Grid.ColumnDefinitions>
                                      <ColumnDefinition Width="Auto" SharedSizeGroup="Column1"/>
                                      <ColumnDefinition Width="Auto" SharedSizeGroup="Column2"/>
                                      <ColumnDefinition Width="Auto" SharedSizeGroup="Column3"/>
                                  </Grid.ColumnDefinitions>
                                  <!-- Assumes MVVM and you wish to bind to properties and commands -->
                                  <TextBlock Grid.Column="0" Text="{Binding ColumnOneText}"/>
                                  <TextBlock Grid.Column="1" Text="{Binding ColumnTwoText}"/>
                                  <TextBlock Grid.Column="2" Text="{Binding ColumnThreeText}"/>
                                  <Button Content="ClickMe" Command="{Binding ButtonExecutionCommand}"/>
                              </Grid>
                          </DataTemplate>
                      </ListBox.ItemTemplate>
                  </ListBox>
                  

                  这是一个巧妙的技巧,也可以应用于您有多个 Grid 实例的其他情况(即:根据这种情况,每个 ListBoxItem 一个)并希望共享一列.

                  This is a neat trick that can also be applied to other cases where you have multiple instances of Grid (ie: one per ListBoxItem as per this case) and want to share a column.

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

                  上一篇:到达最后一项时WP7自动增长列表框 下一篇:如何通过键入在 WPF ListBox 中找到项目?

                  相关文章

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

                      <legend id='t5wj4'><style id='t5wj4'><dir id='t5wj4'><q id='t5wj4'></q></dir></style></legend>
                      • <bdo id='t5wj4'></bdo><ul id='t5wj4'></ul>
                    1. <small id='t5wj4'></small><noframes id='t5wj4'>

                      <tfoot id='t5wj4'></tfoot>