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 ...
随机推荐
- js--事件对象的理解5-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- spring注解支持
Spring基于注解实现Bean定义支持如下三种注解: Spring自带的@Component注解及扩展@Repository.@Service.@Controller JSR-250 1.1版本中中 ...
- 如何使用cygwin去编译cocos2dx项目中的C++文件
将生成的cocos2dx的Android项目导入到eclipse 可以先测试一下如何编译C++项目: 1.打开cygwin,进入到Android项目对应的目录下面去: 2.编译脚本 在编译脚本之间,如 ...
- 遍历(二)javascript的Foreach语法
原文:http://www.cnblogs.com/Fskjb/archive/2011/03/26/1996165.html 首先,虽然叫foreach语法但关键字还是用for哦,这个语法只是对平时 ...
- POJ 2311 Cutting Game(SG+记忆化)
题目链接 #include<iostream> #include<cstdio> #include<cstring> using namespace std; ][ ...
- MySQL数据类型和属性
日期和时间数据类型 MySQL数据类型 含义 date 3字节,日期,格式:2014-09-18 time 3字节,时间,格式:08:42:30 datetime 8字节,日期时间,格式:2014-0 ...
- Mysql表名区分大小写
mysql数据库在windows服务器上表名和字段名均不区分大小写, 但在linux服务器上表名默认是区分大小写的,可在/etc/my.cnf文件中的[mysqld]下面加上一条配置 lower_ca ...
- 使用UGUI实现拖拽功能(拼图小游戏)
实现方式 1.引入UGUI自带的事件系统 UnityEngine.EventSystems 2.为我们的类添加接口 IBeginDragHandler, IDragHandler, IEndDragH ...
- Struts对输入数据的校验
当我们在登录或者是注册时需要对用户输入的数据验证,以前都是浏览器传送数据到后台,后台对数据进行校验,如果有错误就带着错误信息转发带登录或者注册页面, struts可以简便的对输入数据进行校验 首先我们 ...
- agentX各个角色功能
AgentX Roles 1.master An entity acting in a master agent role performs the following functions: - ...