ItemContainerStyleSelector是容器Style选择器

用法和ItemTemplateSelector差不多

同样也是也是继承类 StyleSelector,也是重写方法SelectStyle,参数都是一样的,一是数据,二是数据对象。返回值则是Style,默认值则是Null

XAML也是差不多的,同样使用绑定的语法

选择器类:

public class SelectOFStyle: StyleSelector
{
public int i = ;
public override Style SelectStyle(object item, DependencyObject container)
{
var u = container as FrameworkElement; i++; if (i % == )
return u.FindResource("St1") as Style;
else
return u.FindResource("St2") as Style;
}
}

xaml

 <Window.Resources>
<Storyboard x:Key="S2">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" >
<EasingDoubleKeyFrame KeyTime="" Value=""/>
<EasingDoubleKeyFrame KeyTime="" Value=""/>
<EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="-5"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value=""/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" >
<EasingDoubleKeyFrame KeyTime="" Value=""/>
<EasingDoubleKeyFrame KeyTime="" Value=""/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value=""/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" >
<EasingDoubleKeyFrame KeyTime="" Value=""/>
<EasingDoubleKeyFrame KeyTime="" Value=""/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value=""/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="S1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" >
<EasingDoubleKeyFrame KeyTime="" Value=""/>
<EasingDoubleKeyFrame KeyTime="" Value=""/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value=""/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Style TargetType="ListBoxItem" x:Key="St1">
<Setter Property="RenderTransform" >
<Setter.Value>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Setter.Value>
</Setter>
<Style.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource S2}"/>
</EventTrigger>
</Style.Triggers>
</Style>
<Style TargetType="ListBoxItem" x:Key="St2">
<Setter Property="RenderTransform" >
<Setter.Value>
<TransformGroup>
<ScaleTransform/>
</TransformGroup>
</Setter.Value>
</Setter>
<Style.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource S1 }"/>
</EventTrigger>
</Style.Triggers>
</Style>
<local:Select x:Key="sl2"/>
<local:SelectOFStyle x:Key="sl1"/>
<DataTemplate x:Key="d1">
<Image x:Name="image" Height="" Width="" Source="{Binding Image}" />
</DataTemplate> <DataTemplate x:Key="d2">
<Image x:Name="image" Height="" Width="" Source="{Binding Image}" />
</DataTemplate> </Window.Resources>
<Grid>
<ListBox ItemTemplateSelector="{StaticResource sl2}" ItemContainerStyleSelector="{StaticResource sl1}" x:Name="ListBoxFile" Margin="0,0,0,119" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel> </ListBox>
<Button Click="Button_Click" Margin="451,321,0,0"/> </Grid>

图片效果

ItemContainerStyleSelector的更多相关文章

  1. 项模板选择器属性(ItemTemplateSelector属性)和样式选择器(ItemContainerStyleSelector)

    3.4.5 共享尺寸组 样式选择器: 或者========================================

  2. [WPF系列]-数据邦定之DataTemplate 对 ItemsControl 进行样式和模板处理

    引言   即使 ItemsControl 不是 DataTemplate 所用于的唯一控件类型,将 ItemsControl 绑定到集合仍然很常见. 在 DataTemplate 中有哪些内容一节中, ...

  3. WPF开发的彩票程序(练手好例子) 附源码

    前言 WPF是.NET最新的界面开发库,开发界面非常灵活!但是学习WPF难度也非常大. 应朋友之邀,编写了一个小程序.程序虽小,五脏俱全,WPF开发的灵活性可窥见一斑. 对于新手学习有很好的借鉴意义, ...

  4. WPF使用总结

    ListboxItemContainer样式 一般items控件的项模板 很容易 设置DataTemplate就可以了,比如listbox .但是在选中和失去焦点的时候 却是Windows自带的那种 ...

  5. WPF核心对象模型-类图和解析

    DispatcherObject是根基类,通过继承该类,可以得到访问创建该对象的UI线程的Dispatcher对象的能力.通过Dispatcher对象,可以将代码段合并入该UI线程执行. Depend ...

  6. WPF开发的彩票程序(练手好例子)

    前言 WPF是.NET最新的界面开发库,开发界面非常灵活!但是学习WPF难度也非常大. 应朋友之邀,编写了一个小程序.程序虽小,五脏俱全,WPF开发的灵活性可窥见一斑. 对于新手学习有很好的借鉴意义, ...

  7. WPF数据模板样式选择器

    在使用数据模板样式选择器时,不能设置ItemContainerStyle的属性值,如果设置了该值,那么数据模板样式选择器会失去作用. 在使用数据模板样式选择器时,首先要创建数据模板样式选择器对象,此对 ...

  8. [WPF自定义控件库]简单的表单布局控件

    1. WPF布局一个表单 <Grid Width="400" HorizontalAlignment="Center" VerticalAlignment ...

  9. WinRT ListView间隔变色(一)

    我们知道,在WPF里,MSDN提供了三种方法 1.使用转换器Converter 2.继承ListView类,自己处理 3.使用StyleSelctor 到了WinRT的世界了 1. Winrt中Set ...

随机推荐

  1. Zabbix Agent 自动、主动注册

    简述: 今天来研究一下 Zabbix 的主动注册功能. 当你有十台机器需要监控时,你手动去添加是没有问题的.但是当你有五十台.上百台或更多服务器要监控时,你会怎么做 ? Active Agent Au ...

  2. 浅谈Trigger

  3. emulator: Trying to vcpu execute at eip:6d4053

  4. 10 华电内部文档搜索系统 search04

    上一节我们着重讲解了权限过滤器的使用.这一节讲解一下补充一下Struts 2下面对应的Checkbox的使用.对索引下面的数据进行维护操作,一次可以删除多个.在Struts 2下面使用对应的Check ...

  5. Mysql 使用触发器,把插入的数据在插入到宁一张表里

    CREATE TRIGGER tgr_tablea_insert AFTER //触发器名字 动作在插入数据之后 ON alertinfo //监听哪个表之后触发 FOR INSERT //监听的表的 ...

  6. Linux安装MySQL全过程

    操作系统:CentOS 7.2  64位 mySQL版本:mysql-5.6.35 安装过程: (1)首先从mysql官网下载 MySQL Community Server 安装包. 选择对应的版本( ...

  7. 882. Reachable Nodes In Subdivided Graph

    题目链接 https://leetcode.com/contest/weekly-contest-96/problems/reachable-nodes-in-subdivided-graph/ 解题 ...

  8. 用 Markdown 写作(一)——添加文章页内导航

    Markdown 可以用更简化的标记来写文章,基本的语法可以参考Markdown 语法说明 (简体中文版). 我平时很少按照论文的写法去写博客,说来忏愧,因为很少写技术性的文章,最近看到百度百科和很多 ...

  9. Openssl genrsa命令

    一.简介 生成RSA私有密钥 二.语法 openssl genrsa [-out filename] [-passout arg] [-f4] [-] [-rand file(s)] [-engine ...

  10. 【原创】cython and python for kenlm

    未经允许不可转载 Kenlm相关知识 Kenlm下载地址 kenlm中文版本训练语言模型 如何使用kenlm训练出来的模型C++版本 关于Kenlm模块的使用及C++源码说明 加载Kenlm模块命令 ...