ItemTemplateSelector的中文翻译是模板选择器

是用来选择模板。

他的用法稍有不同,他必须派生于DataTemplateSelector类。

然后重写SelectTemplate这个方法,方法内由两个参数,一是对象所绑定的数据,二是你绑定的元素。方法有返回类型为DataTemplate的,不过默认值为Null

xaml则是通过绑定的方式。

模板选择的用比较广。

这里就介绍默认的使用方式。

通过数据或者对象元素来选择模板

选择器类

using System.Windows;
using System.Windows.Controls; namespace WinMenu
{
public class Select: DataTemplateSelector
{
private int i = ;
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
var u = container as FrameworkElement; i++; if (i % == )
return u.FindResource("d1") as DataTemplate;
else
return u.FindResource("d2") as DataTemplate; }
}
}

xaml代码:

 <Window.Resources>
<local:Select x:Key="sl2"/> <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>
<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>
</Window.Resources>
<Grid>
<ListBox ItemTemplateSelector="{StaticResource sl2}" x:Name="ListBoxFile" Margin="0,0,0,119" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<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>
</ListBox.ItemContainerStyle>
</ListBox>
<Button Click="Button_Click" Margin="451,321,0,0"/> </Grid>

图片

ItemTemplateSelector的更多相关文章

  1. UWP开发入门(八)——聊天窗口和ItemTemplateSelector

    我们平常用的最多的APP可能就是企鹅和微信了.有没有想过聊天窗口如何实现的?本篇我们将简单模拟一个聊天窗口. 聊天窗口大致上就是消息的一个集合列表.集合列表最常见的展现形式无非就是ListView.可 ...

  2. wpf Listbox 设置ItemContainerStyle后,ItemTemplateSelector不能触发

    解决方案: 将Listbox 的ItemTemplateSelector 改为 ItemContainerStyle中ContentPresenter ContentTemplateSelector ...

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

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

  4. wpf ListView DataTemplate方式的鼠标悬停和选中更改背景色

    今天使用wpf技术弄一个ListView的时候,由于需求需要,需要ListView显示不同的数据模板,很自然的使用了DataTemplate方式来定义多个数据模板,并在ListView中使用ItemT ...

  5. WPF Telerik TreeListView样式设计

    Telerik控件 TreeListView 修改其中样式 1.添加TreeListView控件 <telerik:RadTreeView x:Name="ObjecTreeView& ...

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

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

  7. [WPF系列]-数据邦定之DataTemplate 根据对象属性切换模板

      引言 书接上回[WPF系列-数据邦定之DataTemplate],本篇介绍如何根据属性切换模板(DataTemplate)   切换模板的两种方式:   使用DataTemplateSelecto ...

  8. WPF Combobox样式

    <ControlTemplate x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}&qu ...

  9. UWP开发随笔——UWP新控件!AutoSuggestBox!

    摘要 要开发一款优秀的application,控件肯定是必不可少的,uwp就为开发者提供了各种各样的系统控件,AutoSuggestBox就是uwp极具特色的控件之一,也是相对于之前win8.1的ua ...

随机推荐

  1. Linux 登陆提示文字

    /etc/issue是从本地登陆显示的信息 /etc/issue.net是从网络登陆显示的信息 /etc/motd内容由系统管理员确定,常用于通告信息,如计划关机时间的警告等 每次用户登录时,/etc ...

  2. pid文件的作用

    pid文件的作用 一.pid文件的作用 1.pid文件的内容用cat命令查看,可以看到内容只有一行,记录了该进程的ID 2.pid文件的作用防止启动多个进程副本 3.pid文件的原理进程运行后会给.p ...

  3. apt 查询软件

    apt-cache search percona-server apt list percona-server-server-5.6

  4. FreeSWITCH 客户端fs_cli连接设置(acl)

    FreeSWITCH 默认配置只能 在本机连接, 要从 外面连接, 就要配置: acl.conf.xml::network-lists/list event_socket.conf.xml::appl ...

  5. 这几天用高通VUFORIA的体会

    VUFORIA 主要用来做图像识别,先把图片上至网站,然后网站分析生成数据包 在UNITY中导入VUFORIA SDK和数据包后,就可以正常使用了 对了,数据包需要勾选Load Active那个选项, ...

  6. RotbotFrameWork接口测试

    一.添加接口测试Library 二.参数说明 三.关键字使用说明 Set Varibae: 参数化接口地址 Connect To Databse Using Custom Param: 连接数据库(需 ...

  7. poi导出excel表格

    package poiexcel; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; ...

  8. linux进入单用户方法-乾颐堂

    RedHat7.2 在使用GRUB引导程序的时候如何进入单用户 1.在出现GURB引导画面时,按字母e,进入GRUB编辑状态 2在引导菜单后添加“1”或single,选定它,然后按字母b,就可引导到单 ...

  9. qy Undefied index报错

    目测是不支持如下写法 $value['status'] = $map[$value['status']];

  10. bootstrap导航条相关知识

    在导航条(navbar)中有一个背景色.而且导航条可以是纯链接(类似导航),也可以是表单,还有就是表单和导航一起结合等多种形式. 为导航条添加标题.二级菜单及状态 <div class=&quo ...