WPF ListBox按块显示元素 WPF中的ListBox实现按块显示元素的方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

WPF ListBox按块显示元素 WPF中的ListBox实现按块显示元素的方法

永远爱好写程序   2021-03-22 我要评论
想了解WPF中的ListBox实现按块显示元素的方法的相关内容吗,永远爱好写程序在本文为您仔细讲解WPF ListBox按块显示元素的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:WPF,ListBox,按块显示元素,下面大家一起来学习吧。

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

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

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

<ListBox.ItemsPanel>
    <ItemsPanelTemplate>
      <WrapPanel/>
    </ItemsPanelTemplate>
</ListBox.ItemsPanel>

<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>

希望本文所述对大家C#程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们