zoukankan      html  css  js  c++  java
  • WPF中的ListBox实现按块显示元素的方法

    本文实例讲述了WPF中的ListBox实现按块显示元素的方法。分享给大家供大家参考,具体如下:

    注意:需要设置ListBox的属性 ScrollViewer.HorizontalScrollBarVisibility="Disabled"

    关键代码,WPF中有内置的WrapPanel控件,在ListBox.ItemsPanel中使用可以让元素按块显示

    1
    2
    3
    4
    5
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
          <WrapPanel/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    <ListBox Height="304" HorizontalAlignment="Left" Margin="14,143,0,0" Name="lstTables" VerticalAlignment="Top" Width="615" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
      <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
          <WrapPanel/>
        </ItemsPanelTemplate>
      </ListBox.ItemsPanel>
      <ListBox.ItemTemplate>
        <DataTemplate>
          <Grid Margin="20,20,20,20">
            <Grid.RowDefinitions>
              <RowDefinition></RowDefinition>
              <RowDefinition></RowDefinition>
              <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <Image Source="Images/table.png" Grid.Row="0" Height="42" Width="42" HorizontalAlignment="Center">
              <Image.Effect>
                <DropShadowEffect/>
              </Image.Effect>
            </Image>
            <TextBlock Text="{Binding FTableName,Mode=TwoWay}" Grid.Row="1" HorizontalAlignment="Center" Margin="5,5,5,5" />
            <CheckBox IsChecked="{Binding FSelected,Mode=TwoWay,Converter={StaticResource SelCTS}}" Grid.Row="2" HorizontalAlignment="Center">
              <CheckBox.Effect>
                <DropShadowEffect/>
              </CheckBox.Effect>
            </CheckBox>
          </Grid>
        </DataTemplate>
      </ListBox.ItemTemplate>
    </ListBox>
  • 相关阅读:
    面试题:区分List中remove(int index)和remove(Object obj)
    Collection的子接口之一:List 接口
    面试题:ArrayList、LinkedList、Vector三者的异同?
    jdk 5.0 新增的foreach循环(用于遍历集合、数组)
    Iterator迭代器接口(遍历Collection的两种方式之一)
    哈希值
    Collection接口方法
    集合框架的概述
    注解(Annotation)
    System类、Math类、BigInteger与BigDecimal的使用
  • 原文地址:https://www.cnblogs.com/sjqq/p/7918893.html
Copyright © 2011-2022 走看看