ListBox横向排布Item
<Window x:Class="TwoColumnListBox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TwoColumnListBox"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<GridView x:Key="GridView">
<GridView.Columns>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=ModelName}"/>
<GridViewColumn Header="Model" DisplayMemberBinding="{Binding Path=ModelNumber}"/>
<GridViewColumn Header="Price" DisplayMemberBinding="{Binding Path=UnitCost}"/>
</GridView.Columns>
</GridView>
<local:TileView x:Key="ImageView">
<local:TileView.ItemTemplate>
<DataTemplate>
<StackPanel Width="150" VerticalAlignment="Top">
<TextBlock Text="{Binding Path=MockImageStr}"/>
</StackPanel>
</DataTemplate>
</local:TileView.ItemTemplate>
</local:TileView>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<ListView Grid.Row="0" Name="lstProducts">
<ListView.View>
<local:TileView/>
</ListView.View>
</ListView>
<ListBox Grid.Row="1" Name="lstProducts2">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=MockImageStr}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ComboBox x:Name="lstCombox" Grid.Row="2" SelectionChanged="ComboBox_SelectionChanged">
<ComboBoxItem Content="GridView"/>
<ComboBoxItem Content="ImageView"/>
</ComboBox>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 TwoColumnListBox
{
public class TileView : ViewBase
{
DataTemplate _itemTemplate;
public DataTemplate ItemTemplate
{
get
{
return _itemTemplate;
}
set
{
_itemTemplate = value;
}
}
protected override object DefaultStyleKey
{
get
{
return new ComponentResourceKey(GetType(),"TileView");
}
}
protected override object ItemContainerDefaultStyleKey
{
get
{
return new ComponentResourceKey(GetType(), "TileViewItem");
}
}
}
public class ModelInfo
{
public string ModelName
{
get;set;
}
public int ModelNumber
{
get;set;
}
public double UnitCost
{
get;set;
}
public string MockImageStr
{
get;set;
}
}
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var a = new List<ModelInfo>
{
new ModelInfo{ModelName="iPhone 6",ModelNumber=6,UnitCost=549.00,MockImageStr="Iphone6" },
new ModelInfo{ModelName="iPhone 5",ModelNumber=6,UnitCost=549.00,MockImageStr="Iphone5" },
new ModelInfo{ModelName="iPad",ModelNumber=6,UnitCost=549.00,MockImageStr="IPad" },
};
lstProducts.ItemsSource = a;
lstProducts2.ItemsSource = a;
}
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBoxItem selec = (ComboBoxItem)lstCombox.SelectedItem;
lstProducts.View = (ViewBase)this.FindResource(selec.Content);
}
}
}


ListBox横向排布Item的更多相关文章
- WPF,解决Listbox,按住ListboxItem向下拖出Listbox,横向滚动条跑到最后。
类似这种样式的控件,.,在横向滚动条隐藏的情况下有这样的问题.(横向滚动条显示的时候也会,,目前不知道怎么解决.) 因为这个控件偏移是利用ListBox的ItemsPanelTemplate模版里的S ...
- React实现座位排布组件
React实现座位排布组件 最近在开发一个影院系统的后台管理系统,该后台可以设置一个影厅的布局. 后台使用的是react框架,一位大神学长在几天之内就把这个控件研究出来了,并进行了较为严密的封装,佩服 ...
- CSS布局之div交叉排布与底部对齐--flex实现
最近在用wordpress写页面时,设计师给出了一种网页排布图样,之前从未遇到过,其在电脑上(分辨率大于768px)的效果图如下: 而在手机(分辨率小于等于768px)上要求这样排列: 我想到了两种方 ...
- 按照excel文档中的内容在当前cad图纸中自动排布实体
本例实现的主要功能是读取excel文档中的内容,其次是将按照读取的信息在当前cad图纸中添加相应的实体.下面先介绍实现代码: CString excelPath; //外部excel文档的地址 Upd ...
- 实现LinearLayout(垂直布局,Gravity内容排布)
首先上Gravity的代码,Android原版的Gravity搞得挺复杂的,太高端了.但基本思路是使用位运算来做常量,我就自己消化了一些,按自己的思路来实现. 先上代码,在做分析. package k ...
- Python中cv2库和matplotlib库色彩空间排布不一致
今天在python中读如图片时发现以下问题: 1.在from matplotlib import pyplot as plt之后,再import cv2 cv2.imshow()不能正常使用,还不知道 ...
- css 行内水平均等排布方式
<div class="justify"> <span>测试1</span> <span>测试2</span> < ...
- GridView 二维排布
与ListView一维排布相对 public class MainActivity extends Activity implements AdapterView.OnItemClickListene ...
- WPF ListBox 横向排列
WPF ListBox 横向排列 如果只是单纯的让ListBox可以横向配列,这样很简单,只需要更改ListBox的ItemsPanel模板就可以,例如: <ListBox><L ...
- ListView 一维排布 动态滑动添加新item代码
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentV ...
随机推荐
- Spark - [03] 资源调度模式
题记部分 一.Local模式 1.1.概述 Local模式就是运行在一台计算机上的模式,通常就是用于在本机上练手和测试的. 可以通过以下几种方式设置Master (1)local:所欲计算都运行在一个 ...
- 面试题32 - II. 从上到下打印二叉树 II
地址:https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof/ <?php /** 面试题32 ...
- pycharm debug调试【Mute Breakpoints】【Run to Curson】按钮
1.Debug 调试时,红色妞变为灰色怎么办 Mute Breakpoints:哑的断点,选择这个后,所有断点变为灰色,断点失效,按F9则可以直接运行完程序.再次点击,断点变为红色,有效.如果只想使某 ...
- DBeaver连接mysql时Public Key Retrieval is not allowed错误
前言 DBeaver 连接 mysql 时,报错:Public Key Retrieval is not allowed 解决 在新建连接的时候,驱动属性里设置 allowPublicKeyRetri ...
- Failed to start MySQL 8.0 database server.
原因 在mysql错误日志里出现:The innodb_system data file 'ibdata1' must be writable,字面意思:ibdata1必须可写 查看日志报错,文件夹无 ...
- 【SqlServer】datetime存储精度问题探究
最近使用sqlserver 2012的时候注意到datetime类型的毫秒的精度是存在问题的,好奇是怎么回事,特意来研究一下 问题复现 如下的sql执行 UPDATE AlarmItem SET cr ...
- Docker图形化工具Portainer安装
Docker方式安装 我们可以直接使用 **Docker** 的方式来安装 首先创建数据卷,实现数据持久化 docker volume create portainer_db 启动 **Partain ...
- 当Kafka化身抽水马桶:论组件并发提升与系统可用性的量子纠缠关系
<当Kafka化身抽水马桶:论组件并发提升与系统可用性的量子纠缠关系> 引言:一场OOM引发的血案 某个月黑风高的夜晚,监控系统突然发出刺耳的警报--我们的数据发现流水线集体扑街.事后复盘 ...
- 【Linux】速查手册
查看Linux系统信息 arch #显示机器的处理器架构(1) uname -m #显示机器的处理器架构(2) uname -r #显示正在使用的内核版本 dmidecode -q #显示硬件系统部件 ...
- 用 .NET NativeAOT 构建完全 distroless 的静态链接应用
前言 .NET NativeAOT 想必不少开发者都已经很熟悉了,它可以将 .NET 程序集直接编译到原生的机器代码,从而可以脱离 VM 直接运行.简单的一句 dotnet publish -c Re ...