<tfoot id='OmaCV'></tfoot>
  • <small id='OmaCV'></small><noframes id='OmaCV'>

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

        如何为 ListBoxItem 创建标题?

        How do I make a header for a ListBoxItem?(如何为 ListBoxItem 创建标题?)

      1. <tfoot id='2Ydz6'></tfoot>

        <small id='2Ydz6'></small><noframes id='2Ydz6'>

          1. <legend id='2Ydz6'><style id='2Ydz6'><dir id='2Ydz6'><q id='2Ydz6'></q></dir></style></legend>
                <bdo id='2Ydz6'></bdo><ul id='2Ydz6'></ul>

                  <tbody id='2Ydz6'></tbody>
                1. <i id='2Ydz6'><tr id='2Ydz6'><dt id='2Ydz6'><q id='2Ydz6'><span id='2Ydz6'><b id='2Ydz6'><form id='2Ydz6'><ins id='2Ydz6'></ins><ul id='2Ydz6'></ul><sub id='2Ydz6'></sub></form><legend id='2Ydz6'></legend><bdo id='2Ydz6'><pre id='2Ydz6'><center id='2Ydz6'></center></pre></bdo></b><th id='2Ydz6'></th></span></q></dt></tr></i><div id='2Ydz6'><tfoot id='2Ydz6'></tfoot><dl id='2Ydz6'><fieldset id='2Ydz6'></fieldset></dl></div>
                  本文介绍了如何为 ListBoxItem 创建标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在我的应用程序中使用 ListBox.ListBox 有两列.我想为列命名.是布局

                  I use ListBox in my application. ListBox has two columns. I want to make a title for the columns. It is layout

                    <Window.Resources>
                      <Style x:Key="borderBase" TargetType="Border">
                          <Setter Property="BorderBrush" Value="Black" />
                          <Setter Property="BorderThickness" Value="1" />
                      </Style>
                  </Window.Resources>
                  <Grid>
                      <Grid.RowDefinitions>
                          <RowDefinition Height="1*" />
                          <RowDefinition Height="7*" />
                      </Grid.RowDefinitions>
                      <!--  Title  -->
                      <Grid>
                          <Grid.ColumnDefinitions>
                              <ColumnDefinition />
                              <ColumnDefinition />
                          </Grid.ColumnDefinitions>
                  
                          <Border Style="{StaticResource borderBase}">
                              <TextBlock Text="FirstName" />
                          </Border>
                  
                          <Border Grid.Column="1" Style="{StaticResource borderBase}">
                              <TextBlock Text="SecondName" />
                          </Border>
                  
                      </Grid>
                  
                      <!-- Data -->
                      <ListBox Grid.Row="1">
                          <ListBox.ItemTemplate>
                              <DataTemplate>
                  
                                  <Grid>
                                      <Grid.ColumnDefinitions>
                                          <ColumnDefinition />
                                          <ColumnDefinition />
                                      </Grid.ColumnDefinitions>
                  
                                      <Border Style="{StaticResource borderBase}">
                                          <TextBlock Style="{StaticResource textBlockBase}" Text="{Binding FirstName}" />
                                      </Border>
                  
                                      <Border Grid.Column="1" Style="{StaticResource borderRigth}">
                                          <TextBlock Style="{StaticResource textBlockBase}" Text="{Binding SecondName}" />
                                      </Border>
                                  </Grid>
                  
                              </DataTemplate>
                          </ListBox.ItemTemplate>
                      </ListBox>
                  
                  </Grid>
                  

                  当 ListBox 中的几个项目全部显示时 OK.但是当列表中有很多元素时——ListBox 中的垂直滚动条是可见的.然后是标题并跨列的宽度移动.

                  When a few items in the ListBox are all displayed OK. But when a lot of elements in the list - a vertical scroll bar in ListBox is visible. Then the title and move across the width of the columns.

                  如何对齐列和标题的宽度?

                  How to align the width of the columns and headers?

                  推荐答案

                  WPF为此提供了一些属性只是.您需要使用 SharedSizeGroupGrid.IsSharedSizeScope 属性:

                  WPF provides some properties just for this purpose. You need to use the SharedSizeGroup and Grid.IsSharedSizeScope properties:

                  <Grid Grid.IsSharedSizeScope="True"><!-- Look HERE -->
                      <Grid.RowDefinitions>
                          <RowDefinition Height="1*" />
                          <RowDefinition Height="7*" />
                      </Grid.RowDefinitions>
                      <!--  Title  -->
                      <Grid>
                          <Grid.ColumnDefinitions>
                              <ColumnDefinition SharedSizeGroup="FirstNameColumn" /><!-- Look HERE -->
                              <ColumnDefinition />
                          </Grid.ColumnDefinitions>
                          <Border Style="{StaticResource borderBase}">
                              <TextBlock Text="FirstName" />
                          </Border>
                          <Border Grid.Column="1" Style="{StaticResource borderBase}">
                              <TextBlock Text="SecondName" />
                          </Border>
                      </Grid>
                      <!-- Data -->
                      <ListBox Grid.Row="1">
                          <ListBox.ItemTemplate>
                              <DataTemplate>
                                  <Grid>
                                      <Grid.ColumnDefinitions>
                                          <ColumnDefinition SharedSizeGroup="FirstNameColumn" />
                                          <ColumnDefinition /><!--  Look Above HERE  -->
                                      </Grid.ColumnDefinitions>
                                      <Border Style="{StaticResource borderBase}">
                                          <TextBlock Style="{StaticResource textBlockBase}" Text="{Binding FirstName}" />
                                      </Border>
                                      <Border Grid.Column="1" Style="{StaticResource borderRigth}">
                                          <TextBlock Style="{StaticResource textBlockBase}" Text="{Binding SecondName}" />
                                      </Border>
                                  </Grid>
                              </DataTemplate>
                          </ListBox.ItemTemplate>
                      </ListBox>
                  
                  </Grid>
                  

                  请查看 Grid.IsSharedSizeScope 附加属性 MSDN 页面了解更多信息.

                  Please se the Grid.IsSharedSizeScope Attached Property page at MSDN for more information.

                  这篇关于如何为 ListBoxItem 创建标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)

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

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

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