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 ...
随机推荐
- Spring Configuration Check Unmapped Spring configuration files found
Spring Configuration Check Unmapped Spring configuration files found 项目中有xml文件,但没有被用IntelliJ 导入现有工程时 ...
- [cocos2d-x]HelloWorldDemo
实现一个demo,具备以下功能: 1.让几个字分别位于中间和四个角落. 2.中间的字体改变,并且带有闪烁功能. 3.单点触摸和多点触摸,并且能够实现滑动效果,滑动的话必须使用带有bool返回值的单点触 ...
- 菜鸟nginx源代码剖析数据结构篇(一)动态数组ngx_array_t
菜鸟nginx源代码剖析数据结构篇(一)动态数组ngx_array_t Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog.csd ...
- JavaScript-4.6鼠标事件监听,获取鼠标坐标window.event---ShinePans
<html> <head> <meta http-equiv="content-type" content="text/html" ...
- oradebug推进scn
有时候我们遇到例如以下错误: ORA-01092: ORACLE instance terminated. Disconnection forced ORA-00600: internal error ...
- ACM POJ 2192 Zipper
题目大意:输入字符串a,b,c 要求推断c是否有a,b中的个字符保持原有顺序组合而成. 算法思想: DP 用dp[i][j]表示a的前0~i-1共i个字符和b的前0~j-1共j个字符是否构成c[i+j ...
- 14.8.3 Identifying the File Format in Use 确认使用的文件格式;
14.8.3 Identifying the File Format in Use 确认使用的文件格式: 如果 你启用一个不同的文件格式使用 innodb_file_format configurat ...
- 【转】有效修改max open files/ulimit -n
[转]有效修改max open files/ulimit -n_追梦20121222_新浪博客 [转]有效修改max open files/ulimit -n (2011-11-18 0 ...
- App 运营 推广相关
基本要素 1.定位和产品 2.取个好名字,一目了然+下载冲动 3.设计一个好图标,有感性和直观的认识 4.做好产品的说明.关键字,截图(前1-2行是重点) 5.做市场的排名(相关因素如下) (1) ...
- 消息函数一般是私有的,因为不需要程序员显示的调用,但子类如果需要改写这个方法,则改成保护方法Protected
许多的面向对象程序设计语言都支持对消息的处理.消息处理是一种动态响应客户类发出的请求,它与过程调用不同.过程调用中,客户类必须知道服务类提供了哪些过程,以及每个过程的调用约定,并且在调用时需要明确指出 ...