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 ...
随机推荐
- Constraint where both columns cannot be null, but one can
ALTER TABLE TableA ADD CONSTRAINT CK_BothDepartsNotNull CHECK (departA IS NOT NULL OR departB IS NOT ...
- screen 对象当当获取屏幕而已 innethtml可以知道调整屏幕宽度
<div id='lidepeng' style="height: 100px;width: 100px;"></div><script type=& ...
- 4、mybatis动态sql+struts2(通配符+全局配置+分页)
1.创建userinfo.sql数据库脚本 create table USERINFO ( id NUMBER not null, uname ), password ), age NUMBER ) ...
- linux 移除svn文件夹
find . -name .svn -type d -exec rm -fr {} \;
- BestCoder Round #85 A B C
本来没有写博客的打算,可是看完了题解感觉这三道题这么水,我却只做出来一道,实在不应该,还是写点东西吧…… A.sum 问题描述 给定一个数列,求是否存在连续子列和为m的倍数,存在输出YES,否则输出N ...
- Gentoo:Xorg:Failed to load module "……" 问题
错误描述: 安装完xorg-server后,startx启动桌面环境,出现缺少模块错误. Xorg:Failed to load module "--" 查看log: cat /v ...
- Python 学习笔记12
不积跬步,无以至千里.不积小流,无以成江河. 当我觉得沮丧.绝望的时候,就疯狂的敲代码,这样会好受一点. 今天和昨天敲了两天的小程序,算是对python的具体语法规则有个初步的手熟. http://w ...
- 消除警告"property access result unused - getters should not be used for side effects"
我写了如下一段代码: - (void)btnClicked:(UIButton *)button { switch (button.tag) { : self.initShare; break; de ...
- 【java学习】Servlet简单的表单程序(一)
此文用于java学习,在此小记. 在此小Demo中使用到了Servlet,所以有必要了解一下Servlet的相关知识.(Servlet的相关知识摘抄自http://blog.csdn.net/jiuq ...
- 执行 npm run update-webdriver 提示文件不能获取错误
按照angularjs官网的入门教程中输入 npm run update-webdriver 总是提示 https://chromedriver.storage.googleapis.com/2.1 ...