wpf之ListBox横向显示所有ListBoxItem
Xaml:
<Window x:Class="WpfApplication6.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ListBox x:Name="lb">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" Margin="2"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; namespace WpfApplication6
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Person p1 = new Person { Name="张三",Age=};
Person p2 = new Person { Name = "李四", Age = };
Person p3 = new Person { Name = "王五", Age = };
List<Person> list = new List<Person>();
list.Add(p1);
list.Add(p2);
list.Add(p3);
lb.ItemsSource = list;
}
} public class Person
{
private string name; public string Name
{
get { return name; }
set { name = value; }
} private int age; public int Age
{
get { return age; }
set { age = value; }
} }
}
运行效果:

wpf之ListBox横向显示所有ListBoxItem的更多相关文章
- WPF中ListBox的项ListBoxItem被选中的时候Background变化
使用WPF 中ListBox,点击ListBoxItem的时候,自定义它的背景色,曾经在网上找了一些方法, 不是很理想,后来在StackOverflow上找到了,贴出代码和效果图: 效果图:
- WPF MultiSelect模式下ListBox 实现多个ListBoxItem拖拽
WPF 的ListBox不支持很多常见的用户习惯,如在Explorer中用鼠标可以选择多项Item,并且点击已经选择的Item,按住鼠标左键可以将所有已选择Item拖拽到指定的位置.本文简单的实现了这 ...
- WPF ListBox 横向排列
WPF ListBox 横向排列 如果只是单纯的让ListBox可以横向配列,这样很简单,只需要更改ListBox的ItemsPanel模板就可以,例如: <ListBox><L ...
- WPF DataGrid横向显示
前言 利用各种变换,将其水平改向至横向显示. 注意的是要固定好单元格的高宽,或者手动编写style 否者在滚动的时候,会有高宽比例不一样的时候 再其次,要注意datagrid的容器或者datagrid ...
- WPF中ListBox的绑定
WPF中列表式控件派生自ItemsControl类,继承了ItemsSource属性.ItemsSource属性可以接收一个IEnumerable接口派生类的实例作为自己的值(所有可被迭代遍历的集合都 ...
- 转:WPF中ListBox的创建和多种绑定用法
先从最容易的开始演示ListBox控件的创建. Adding ListBox Items下面的代码是向ListBox控件中添加多项ListBoxItem集合.XAML代码如下:<ListBox ...
- WPF图片浏览器(显示大图、小图等)
原文:WPF图片浏览器(显示大图.小图等) 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/wangshubo1989/article/details ...
- listbox横向排列
在Listbox中横向显示CheckBox 前台代码 <ListBox Height=" > <StackPanel x:Name="sp" Orien ...
- WPF 自定义ListBox
如题,要实现一个如下的列表,该如何实现? 在设计过程中,会遇到如下问题: 1.ListBox中ListBoxItem的模板设计 2.ListBox中ListBoxItem的模板容器设计 3.List ...
随机推荐
- 彻底解决tap“点透”,提升移动端点击响应速度
申明!!!最后发现判断有误,各位读读就好,正在研究中.....尼玛水太深了 前言 近期使用tap事件为老夫带来了这样那样的问题,其中一个问题是解决了点透还需要将原来一个个click变为tap,这样的话 ...
- hdu_5832_A water problem(模拟)
题目链接:hdu_5832_A water problem 这是一个惨痛的教训,想这种这么大的大数肯定就是找个规律模拟一下. 然而我们队还写JAVA,用大数艹了13发罚时,真是TM智障了. #incl ...
- Unity开发Oculus游戏
1.下载Oculus对应自己操作系统的SKD&RunTime 下载地址 我这里是window系统,下载的是0.6.0.0版本的 2.安装RunTime,电脑右下角状态栏会出现一个小眼睛表示安装 ...
- #include 和 #pragma comment 的相对路径起点
#include 是以当前文件所在路径为当前目录 #pragma comment 是以当前工程所在路径为当前目录 #include "../../../../ThirdParty/Inclu ...
- Rational Rose 2003 逆向工程转换C++ / VC++ 6.0源代码成UML类图
目录 1.安装&破解Rational Rose 2003 1.1 安装Rose 2003 1.2 破解Rose 2003 1.3运行出错“没有找到suite objects.dl” 2. Ra ...
- NOIP2005-普及组复赛-第一题-陶陶摘苹果
题目描述 Description 陶陶家的院子里有一棵苹果树,每到秋天树上就会结出10个苹果.苹果成熟的时候,陶陶就会跑去摘苹果.陶陶有个30厘米高的板凳,当她不能直接用手摘到苹果的时候,就会踩到板凳 ...
- FbinstTool(U盘启动盘制作工具) v1.606 免费绿色版
软件名称: FbinstTool(U盘启动盘制作工具) v1.606 免费绿色版软件语言: 简体中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 / WinXP / W ...
- beginBackgroundTaskWithExpirationHandle
[[UIApllication sharedApplication] beginBackgroundTaskWithExpirationHandle:^{}];这个方法在app进入后台时,可以做一些事 ...
- drupal7 开发block
在自己开发的模块的module文件中,实现两个钩子:hook_block_info()和hook_block_view() function journal_block_info() { $block ...
- js 中null 和 undifined
1.一个重要问题 null == undifined (true) ; null === undefined (false) 为什么是这样的呢? undifined是未赋值的基本数据类型,未定义: n ...