如何实现WPF ListBox按块展示元素的功能?

2026-05-23 19:091阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计460个文字,预计阅读时间需要2分钟。

如何实现WPF ListBox按块展示元素的功能?

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

注意:需要设置ListBox的属性 ScrollViewer.HorizontalScrollBarVisibility=Disabled关键代码:WPF中有内置的Block类

简化版:本文介绍WPF中ListBox按块显示元素的方法。设置属性 ScrollViewer.HorizontalScrollBarVisibility=Disabled,使用内置的Block类。

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

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

如何实现WPF ListBox按块展示元素的功能?

关键代码,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#相关内容感兴趣的读者可查看本站专题:《C#窗体操作技巧汇总》、《C#常见控件用法教程》、《WinForm控件用法总结》、《C#程序设计之线程使用技巧总结》、《C#操作Excel技巧总结》、《C#中XML文件操作技巧汇总》、《C#数据结构与算法教程》、《C#数组操作技巧总结》及《C#面向对象程序设计入门教程》

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

标签:

本文共计460个文字,预计阅读时间需要2分钟。

如何实现WPF ListBox按块展示元素的功能?

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

注意:需要设置ListBox的属性 ScrollViewer.HorizontalScrollBarVisibility=Disabled关键代码:WPF中有内置的Block类

简化版:本文介绍WPF中ListBox按块显示元素的方法。设置属性 ScrollViewer.HorizontalScrollBarVisibility=Disabled,使用内置的Block类。

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

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

如何实现WPF ListBox按块展示元素的功能?

关键代码,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#相关内容感兴趣的读者可查看本站专题:《C#窗体操作技巧汇总》、《C#常见控件用法教程》、《WinForm控件用法总结》、《C#程序设计之线程使用技巧总结》、《C#操作Excel技巧总结》、《C#中XML文件操作技巧汇总》、《C#数据结构与算法教程》、《C#数组操作技巧总结》及《C#面向对象程序设计入门教程》

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

标签: