博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
wpf之ListBox中ListBoxItem横向排列
阅读量:6657 次
发布时间:2019-06-25

本文共 6347 字,大约阅读时间需要 21 分钟。

ListBox中ListBoxItem默认是纵向排列,可以通过自定义样式,让其横向排列,

如下Demo:

 

XAML:

View Code

 

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;using System.Collections.ObjectModel;using System.ComponentModel;namespace ListBoxItemStyleDemo{    ///     /// MainWindow.xaml 的交互逻辑(横着放ListBoxItem)    ///     public partial class MainWindow : Window,INotifyPropertyChanged    {        private string terminalName;        ///         /// 机台(站点)        ///         public string TerminalName        {            get { return terminalName; }            set             {                terminalName = value;                OnPropertyChanged("TerminalName");            }        }        private DateTime productionDay;        ///         /// 工作日        ///         public DateTime ProductionDay        {            get { return productionDay; }            set             {                productionDay = value;                OnPropertyChanged("ProductionDay");            }        }        private string shiftName;        ///         /// 班次        ///         public string ShiftName        {            get { return shiftName; }            set { shiftName = value; }        }        private ObservableCollection
cars; ///
/// 汽车集合 /// public ObservableCollection
Cars { get { if (cars==null) { cars = new ObservableCollection
(); } return cars; } } private Car selectedCar; ///
/// 选中的汽车 /// public Car SelectedCar { get { return selectedCar; } set { selectedCar = value; OnPropertyChanged("SelectedCar"); } } public MainWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { this.TerminalName = "24#站点"; this.ProductionDay = DateTime.Now; this.ShiftName = "早班"; this.Cars.Add(new Car { CarNo = "0001#", CarName = "秋刀鱼牌汽车", WorkOrder = "20160402A", Customer = "TYDF86" }); this.Cars.Add(new Car { CarNo = "0002#", CarName = "武昌鱼牌汽车", WorkOrder = "20160402A", Customer = "SEDF75" }); this.Cars.Add(new Car { CarNo = "0003#", CarName = "金枪鱼牌汽车", WorkOrder = "20160403A", Customer = "CKDF34" }); this.Cars.Add(new Car { CarNo = "0004#", CarName = "沙丁鱼牌汽车", WorkOrder = "20160404A", Customer = "RSDF21" }); this.Cars.Add(new Car { CarNo = "0005#", CarName = "三文鱼牌汽车", WorkOrder = "20160405A", Customer = "YRDF56" }); } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string propertyName) { if (this.PropertyChanged!=null) { this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } } public class Car:INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string propertyName) { if (this.PropertyChanged != null) { this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } private string workOrder; ///
/// 工单号 /// public string WorkOrder { get { return workOrder; } set { workOrder = value; OnPropertyChanged("WorkOrder"); } } private string carNo; ///
/// CarNo /// public string CarNo { get { return carNo; } set { carNo = value; OnPropertyChanged("CarNo"); } } private string carName; ///
/// 品牌 /// public string CarName { get { return carName; } set { carName = value; OnPropertyChanged("CarName"); } } private string customer; ///
/// 客户代码 /// public string Customer { get { return customer; } set { customer = value; OnPropertyChanged("Customer"); } } }}
View Code

 

运行效果:

 

选择“0003#”:

 

总结:

   设置ListBox的属性如下:

 

则ListBox的ListBoxItem横向排列。

转载于:https://www.cnblogs.com/527289276qq/p/5417326.html

你可能感兴趣的文章
[]为false,!![]为true,[true] == 'true'为true,傻傻分不清
查看>>
【译】Gradle 的依赖关系处理不当,可能导致你编译异常
查看>>
[译]无脚本的脚本:比特币如何支持没有智能合约的智能合约
查看>>
最全阿里技术P系列解读:P5-P8的技能要求和薪资结构
查看>>
老司机带你检测相似图片
查看>>
逆向基础(十三) JAVA (一)
查看>>
深入分析 Fiesta Exploit Kit
查看>>
IQKeyboard导航栏上移和键盘遮盖textfield的问题
查看>>
Swift中Initialization的一些个人总结
查看>>
Fiddler安装https证书
查看>>
JS迭代器模式《JavaScript设计模式与开发实践》阅读笔记
查看>>
opencv python 图像轮廓/检测轮廓/绘制轮廓
查看>>
Redis 不能不了解的小功能(二)
查看>>
180607-手写定长数组
查看>>
Unity中解决JsonUtility转换数组失败的BUG
查看>>
[LeetCode] Shuffle an Array
查看>>
vue的事件委托实现
查看>>
Quartz job scheduler 学习
查看>>
2018免费的隐私保护工具
查看>>
Unity3D游戏引擎为何能让游戏发烧友如此痴狂
查看>>