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 ...
随机推荐
- CentOS安装nginx服务器及配置反向代理
以下是在CentOS上安装nginx服务器并配置反向代理的步骤: 更新系统软件包: sudo yum update 安装nginx: sudo yum install nginx 启动nginx服务: ...
- Flink - [03] API
使用scala编写flink api从不同的数据源(源端)读取数据,并进行无界流/有界流的数据处理,最终将处理好的数据sink到对应的目标端 一.maven配置 <?xml version=&q ...
- Scala样例类及底层实现伴生对象
package com.wyh.day01 /** * 样例类的使用 * 1.使用case修饰类 * 2.不需要写构造方法,getter,setter方法,toString方法 * 3.直接通过对象名 ...
- 使用 SK 进行向量操作
先祝大家 2025 新年好. 在 2024 年落地的 LLM 应用来看,基本上都是结合 RAG 技术来使用的.因为绝大多数人跟公司是没有 fine-turning 的能力的.不管是在难度还是成本的角度 ...
- SuperSocket 服务端 和 SuperSocket.ClientEngine 客户端及普通客户端
internal class Program { //static void Main(string[] args) //{ // byte[] arr = new byte[1024]; // 1. ...
- pandas 删除指定条件的行
inplace=True:不创建新的对象,直接对原始对象进行修改: inplace=False:对数据进行修改,创建并返回新的对象承载其修改结果. 删除工作日餐补为0的记录 row_index=df[ ...
- 【Python】配置pip使用国内镜像源
配置pip使用国内镜像源 零.问题 使用pip安装插件时总是很慢,咋解决呢? 壹.解决 在桌面上你的文件夹内新建pip目录,一般路径如下:C:\Users\{$你的用户名},比如我的用户名是Minuy ...
- Web前端入门第 31 问:CSS background 元素背景图用法全解
background 可设置背景色.渐变.背景图等,本文主要讲解背景图片的用法. 背景顾名思义就是背后的景色,始终居于元素背后,元素永远站在背景的身前. 本文示例中所使用的图片: background ...
- 基于transformer的机器翻译:手把手教你实现
目录 前言 transformer模型的搭建 Input embedding Encoder Decoder output transformer构建 data数据集处理 train config 参 ...
- springboot整合log4j
一.默认名log4j2-spring.xml,就省下了在application.yml中配置 <console name="Console" target="SYS ...