在Resource中使用x:Bind
Build2015上,MS热情高涨的演示了x:Bind,一种新的Binding方式,新的方式有如下优点:
1更好的性能(内存占用,CPU占用)
2BuildTime的Binding
具体在Channel9有视频
Data Binding: Boost Your Apps' Performance Through New Enhancements to XAML Data Binding
新的绑定方式,有如下特点:
x:Bind 主要的几点:
1. 强类型
2.上下文为page 或 UserControl
3.绑定的默认Mode为OneTime
更多了解,请访问:
其它的都比较简单,本文主要讲解在Resource中使用x:Bind
1.定义一资源文件DataTemplaterResources.xaml
<ResourceDictionary
x:Class="SLWeek.CustomTheme.DataTemplaterResources"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:behaviors="using:MVVMSidekick.Behaviors"
xmlns:controls="using:Q42.WinRT.Controls"
xmlns:models="using:SLWeek.Models">
</ResourceDictionary>
注意:要使用x:Class,命名此xmal的部分类,与下面.cs文件从命名空间和类名称上保持一致
2.定义同名的部分类DataTemplaterResources.xaml.cs
namespace SLWeek.CustomTheme
{
public partial class DataTemplaterResources
{
public DataTemplaterResources()
{
InitializeComponent();
}
}
}
注意:一定要在构造函数中使用初始化InitializeComponent();
其结构如下图所示

3.引用资源文件,我们可以在页面引用,也可以直接在APP.xaml中引用,引用方式,不是我们通常的ResourceDictionary,而是如下方式:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light" Source="CustomTheme/ThemeResourcesLight.xaml" />
<ResourceDictionary x:Key="Dark" Source="CustomTheme/ThemeResourcesDark.xaml" />
</ResourceDictionary.ThemeDictionaries>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="CustomTheme/CustomStyleResources.xaml" />
<ResourceDictionary Source="CustomTheme/FlatUIColorsResources.xaml" />
<theme:DataTemplaterResources/>
</ResourceDictionary.MergedDictionaries> </ResourceDictionary>
</Application.Resources>
其中theme是为我们为其所有命名空间起的别名
4.我们可以根据业务需要,在Resource中添加自己需要的Datatemplate了
<DataTemplate x:Key="PostDetailItemDataTemplate" x:DataType="models:PostDetail">
<Grid Margin="0,5,0,5" Background="{ThemeResource SystemControlChromeLowBackgroundBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height=""/>
<RowDefinition Height=""/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=""/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<behaviors:SendToEventRouterAction EventRoutingName="NavToPostDetailByEventRouter" IsEventFiringToAllBaseClassesChannels="True" EventData="{Binding}"/>
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
<Image controls:ImageExtensions.CacheUri="{x:Bind Icon}" Stretch="Fill" Grid.Row="" Grid.Column="" Grid.ColumnSpan=""/>
<!--<c:DelayLoadImage DefaultImageSource="../Assets/Icon/no.png" ActualImageSource="{Binding Icon}" Stretch="Fill" Grid.Row="" Grid.ColumnSpan=""/>-->
<TextBlock Text="{x:Bind Creattime,Converter={StaticResource StringFormatConverter},ConverterParameter='{}{0:MMM dd}',Mode=OneWay}" FontSize="" Grid.Row="" Grid.Column="" Grid.RowSpan="" Margin="0,10,0,0"/>
<TextBlock Text="{x:Bind Title}" FontSize="" Grid.Row="" Grid.Column="" Margin="0,2,0,2"/>
<TextBlock Text="{x:Bind Des}" TextTrimming="CharacterEllipsis" Style="{StaticResource MenuTitleTextBlockStyle}" Grid.Row="" Grid.Column="" Margin="0,10" VerticalAlignment="Stretch"/>
</Grid>
</DataTemplate>
注意,由于x:Bind是强类型,我们需要在Datatempalte声明中 使有 x:DataType="models:PostDetail" 来确定要绑定的数据类型,
5.在页面中引用这个资源即可
<ListView ItemsSource="{x:Bind StrongTypeViewModel.SoureList}" Style="{StaticResource ListViewWrapItemsPanel}" ItemTemplate="{StaticResource PostDetailItemDataTemplate}" SizeChanged="ListView_SizeChanged"/>
最后效果图如下:

在Resource中使用x:Bind的更多相关文章
- 关于angular的$resource中的isArray属性问题
在之前的文章中讲到了在使用$resource的时候,有一个isArray属性. 这个属性在两个地方有提到: 1. angular学习笔记(二十八)-$http(6)-使用ngResource模块构建R ...
- angular学习笔记(二十八-附1)-$resource中的资源的方法
通过$resource获取到的资源,或者是通过$resource实例化的资源,资源本身就拥有了一些方法,$save,$delete,$remove,可以直接调用来保存该资源: 比如有一个$resour ...
- 深入理解jQuery中live与bind方法的区别
本篇文章主要是对jQuery中live与bind方法的区别进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助 注意如果是通过jq添加的层和对象一定要用live(),用其他的都不起作用 ...
- javascript中call,apply,bind的用法对比分析
这篇文章主要给大家对比分析了javascript中call,apply,bind三个函数的用法,非常的详细,这里推荐给小伙伴们. 关于call,apply,bind这三个函数的用法,是学习java ...
- 白话$resource,$resource中的增删改查
前言 $resource详解,在学习angular的过程中,我们已经知道,$http能十分便捷的为我们实现与后端的数据交互,格式如下: $http({method:'GET'},url:'XX').t ...
- C++11中的std::bind
C++11中的std::bind 最近在看看cocos2dx的源代码,发现了cocos2dx 3.0相对于2.0改动了很多,最大的改变就是大量的使用了C++11的特性,比如auto等.其中有一个关于回 ...
- 创建dynamics CRM client-side (十三) - 在HTML Web Resource中获取form elements & 获取外部js文件
上一节我们讨论到创建HTML Web Resource. 但是纯HTML的页面不能满足我们的需求, 所以今天我们来做在HTML Web Resource中获取form elements Please ...
- angular学习笔记(二十八-附2)-$http,$resource中的promise对象
下面这种promise的用法,我从第一篇$http笔记到$resource笔记中,一直都有用到: HttpREST.factory('cardResource',function($resource) ...
- vs2012中将图片放到resource中进行调用
1.在项目中新建一个名叫resource的文件夹,然后将所需图片信息放入该文件夹,如图 2.右击该项目,选择属性->资源选项卡,步骤如图所示 点击添加现有文件,然后找到你刚刚添加的resourc ...
随机推荐
- 011 router backup
Router>en Router#config t Enter configuration commands, one per line. End with CNTL/Z. Router(co ...
- 附录A 思科互联网络操作系统(IOS)
思科互联网络操作系统(IOS) 要点 实现IP编址方案和IP服务,以满足中型企业分支机构网络的网络需求 口在路由器上配置和验证 DHCP和DNS 以及排除其故障(包括 CLI/SDM ). 口配置和验 ...
- Windows 7 SID 修改
在安裝Windows系統時會產生一個獨一無二的SID (Security ID),它用來識別每一部主機,若在同一個區域網路內有兩部相同SID的主機,會出現警告訊息.一般而言,每次安裝時的SID不可能會 ...
- FlashBuilder 4.7 非正常关闭导致的不能启动的解决的方法
停电.或者卡死.FB就不能正常启动了. 以下是老外给出的方法,好用: 进入.metadata/.plugins/org.eclipse.core.resources 文件夹 删除.snap文件 假设是 ...
- 32位win7系统下配置IIS遇到php-cgi.exe - FastCGI 进程意外退出问题的解决的方法
今天重装了一下系统,是32位的WIN7.装完系统后想把IIS装回来,由于有时候须要用到笔记本处理一些事情.结果WEBserver正常了.但IIS的FASTCGI模块始终不能解析PHP,一直报php-c ...
- protobuf入门
,step1:准备.proto文件 syntax = "proto3"; message gps_data { int64 id = 1; string terminalId = ...
- oracle导入命令,记录一下 数据库日志太大,清理日志文件
oracle导入命令,记录一下 工作中用到了,这个命令,记录一下,前提要安装imp.exe imp PECARD_HN/PECARD_HN@127.0.0.1:1521/orcl file=E:\wo ...
- union关键字及大小端模式
1. union 关键字 union 维护足够的空间来置放多个数据成员中的“一种”,而不是为每一个数据成员配置空间,在 union 中所有的数据成员共用一个空间,同一时间只能储存其中一个数据成员,所有 ...
- salt-stack "No Top file or external nodes data matches found"解决
salt-stack在配置分组时提示如下信息: No Top file or external nodes data matches found 后来在官网上找到如下提示,意思是需要重启master服 ...
- 2016/1/22 3,将id为005的对象从集合中移除
package shuzu; public class Emp { private String id; private String name; public Emp(String id, Stri ...