WPF自定义ListBox样式
<!--竖向--> <Style x:Key="ListBoxStyle1" TargetType="{x:Type ListBox}"> <Setter Property="ItemTemplate"> <Setter.Value> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*" SharedSizeGroup="MiddleCoiumn"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="60"/> </Grid.RowDefinitions> <TextBlock FontSize="16" VerticalAlignment="Center" Margin="5" FontStyle="Italic" Grid.Column="0" Text="Country:"/> <TextBlock FontSize="16" VerticalAlignment="Center" Margin="5" Grid.Column="1" Text="{Binding Name}" FontWeight="Bold"/> <Border Margin="4,0" Grid.Column="2" BorderThickness="2" CornerRadius="4"> <Border.BorderBrush> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <GradientStop Offset="0" Color="#aaa"/> <GradientStop Offset="1" Color="#222"/> </LinearGradientBrush> </Border.BorderBrush> <Grid> <Rectangle> <Rectangle.Fill> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <GradientStop Offset="0" Color="#444"/> <GradientStop Offset="1" Color="#fff"/> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <Image Width="48" Margin="2,2,2,1" Source="{Binding ImagePath}"/> </Grid> </Border> </Grid> </DataTemplate> </Setter.Value> </Setter> <Setter Property="Grid.IsSharedSizeScope" Value="True"/> </Style> <!--横向--> <Style x:Key="ListBoxStyle2" TargetType="{x:Type ListBox}" BasedOn="{StaticResource ListBoxStyle1}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListBox}"> <ScrollViewer HorizontalScrollBarVisibility="Auto"> <StackPanel Name="StackPanel1" IsItemsHost="True" Orientation="Horizontal"/> </ScrollViewer> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="VerticalAlignment" Value="Center"></Setter> </Style> <!--平铺--> <Style x:Key="ListBoxStyle3" TargetType="{x:Type ListBox}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListBox}"> <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled"> <WrapPanel IsItemsHost="True"/> </ScrollViewer> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="ItemTemplate"> <Setter.Value> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="140"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="60"/> <RowDefinition Height="30"/> </Grid.RowDefinitions> <Image Grid.Row="0" Width="48" Margin="2,2,2,1" Source="{Binding ImagePath}"/> <TextBlock Grid.Row="1" FontSize="14" HorizontalAlignment="Center" Margin="5" Text="{Binding Name}"/> </Grid> </DataTemplate> </Setter.Value> </Setter> </Style>
应用
<Grid >
<ListBox ItemsSource="{Binding}" Margin="10" Style="{StaticResource ListBoxStyle3}"></ListBox>
</Grid>
数据支持:
public partial class 数据模板 : Window { public 数据模板() { InitializeComponent(); this.DataContext = Countries.GetCountry(); } } public class Country { public string Name { get; set; } public string ImagePath { get; set; } public override string ToString() { return Name; } } public class Countries { public static IEnumerable<Country> GetCountry() { return new List<Country> { new Country { Name = "Austria1",ImagePath = "1.jpg"}, new Country { Name = "Austria2",ImagePath = "1.jpg"}, new Country { Name = "Austria3",ImagePath = "1.jpg"}, new Country { Name = "Austria4",ImagePath = "1.jpg"}, }; } }
WPF自定义ListBox样式的更多相关文章
- WPF 自定义ComboBox样式,自定义多选控件
原文:WPF 自定义ComboBox样式,自定义多选控件 一.ComboBox基本样式 ComboBox有两种状态,可编辑和不可编辑状态.通过设置IsEditable属性可以切换控件状态. 先看基本样 ...
- WPF自定义Window样式(2)
1. 引言 在上一篇中,介绍了如何建立自定义窗体.接下来,我们需要考虑将该自定义窗体基类放到类库中去,只有放到类库中,我们才能在其他地方去方便的引用该基类. 2. 创建类库 接上一篇的项目,先添加一个 ...
- WPF自定义Window样式(1)
1. 引言 WPF是制作界面的一大利器.最近在做一个项目,用的就是WPF.既然使用了WPF了,那么理所当然的,需要自定义窗体样式.所使用的代码是在网上查到的,遗憾的是,整理完毕后,再找那篇帖子却怎么也 ...
- WPF 自定义MenuItem样式
原文:WPF 自定义MenuItem样式 一.前言 默认的MenuItem样式比较普通,这次自定义MenuItem的样式也只是对MenuItem的颜色风格进行变化.需要其他功能的变化,大家可以根据样式 ...
- WPF自定义TabControl样式
WPF自定义TabControl,TabControl美化 XAML代码: <TabControl x:Class="SunCreate.Common.Controls.TabCont ...
- WPF 自定义滚动条样式
先看一下效果: 先分析一下滚动条有哪儿几部分组成: 滚动条总共有五部分组成: 两端的箭头按钮,实际类型为RepeatButton Thumb 两端的空白,实际也是RepeatButton 最后就是Th ...
- WPF 自定义CheckBox样式
自定义CheckBox样式,mark一下,方便以后参考复用 设计介绍: 1.一般CheckBox模板太难看了,肯定要重写其中的模板 2.模板状态为未选中状态和选中状态,设置为默认未选中就好了. 默认状 ...
- WPF 自定义ListBox
如题,要实现一个如下的列表,该如何实现? 在设计过程中,会遇到如下问题: 1.ListBox中ListBoxItem的模板设计 2.ListBox中ListBoxItem的模板容器设计 3.List ...
- WPF 自定义ComboBox样式
一.ComboBox基本样式 ComboBox有两种状态,可编辑和不可编辑状态.通过设置IsEditable属性可以切换控件状态. 先看基本样式效果: 基本样式代码如下: <!--ComboBo ...
随机推荐
- windows lwp 乱码问题
use LWP::UserAgent; use Encode; my $ua = LWP::UserAgent->new; $phone=$ARGV[0]; $cc=$ARGV[1]; $ua- ...
- 基于visual Studio2013解决面试题之0604O(1)时间复杂度删除链表节点
题目
- 基于visual Studio2013解决C语言竞赛题之1058打印数字
题目 解决代码及点评 /************************************************************************/ /* 58 ...
- 王立平--PopupWindow
MainActivity.java <span style="font-size:14px;">package com.main; import android.app ...
- Nginx负载均衡:分布式/热备Web Server的搭建
Nginx是一款轻量级的Web server/反向代理server及电子邮件(IMAP/POP3)代理server.并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开 ...
- JQuery - 点击,滚动回到顶部 / 底部刷新回到顶部
if ($(document).scrollTop() != 0) { //刷新之后,回到顶部 $('body,html').animate({ scrollTop: 0 }, 500); }
- 基于visual Studio2013解决面试题之0402合并升序链表并去重
题目
- v$lock 视图访问慢解决方法
V$ 视图访问慢 --解决方法 分析:可能是有数据字典统计信息过久,造成. exec dbms_stats.gather_fixed_objects_stats; ------收集所有数据字典的fix ...
- 谈谈Ext JS的组件——布局的用法续二
绝对布局(Ext.layout.container.Absolute) 绝对布局让我回忆到了使用Foxpro开发的时候,哪时候的界面布局就是这样.通过设置控件的左上角坐标(x.y)和宽度来进行的,由于 ...
- Swift代码实现加载WEBVIEW
let webview = UIWebView(frame:self.view.bounds) webview.bounds=self.view.bounds //远程网页 webview.loadR ...