欢迎来到天天文库
浏览记录
ID:5269011
大小:225.07 KB
页数:5页
时间:2017-12-07
《xaml学习笔记(资源(resources))》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、一.资源(Resources)1.XAML中定义资源的语法格式如下:<根元素对象.Resources><资源定义/>根元素对象.Resources>在Windows8Metro应用开发中,每个Framework对象都支持Resources属性。也就是说,可以在不同控件或者页面定义特定的Resources。例如,在Grid和Button中定义Resources:2、pColor="Yellow"Offset="0.0"/>....2.XAML资源字典(ResourceDictionary)XAML资源的概念在一定程度上简化了XAML页面代码,对于管理批量资源代码集合,XAML
2、pColor="Yellow"Offset="0.0"/>
3、还提供资源字典标记进行声明。在Windows8Metro应用开发中,所有能够被定义在资源字典(ResourceDictionary)的对象必须是可被共享使用的。可以被应用于资源字典的对象如下(来自MSDN):1.StyleandTemplate2.BrushesandColors3.Animationtypes(Storyboard)4.Transforms5.MatrixandMaxtrix3D6.Point7.ThicknessandCornerRadius8.XAMLintrinsicdatatypes3.XAML资源字典
4、(ResourceDictionary)的定义在资源字典(ResourceDictionary)中,每一个资源项必须定义x:Key,也就是所谓的唯一标识的资源名称,这样可以方便读取访问。例如以下代码,在Grid.Resources中定义资源x:Key="bgBrush",我们可以在Button中调用资源x:Key,应用资源到控件。定义资源字典的方法:方法一:在XAML中定义资源字典5、"StartPoint="0.5,0"EndPoint="0.5,1">6、0"Width="120"Margin="112,23,168,217"/>方法二:在后台代码中定义资源字典(ResourceDictionary)ResourceDictionarydict=newResourceDictionary();LinearGradientBrushbgBrush=newLinearGradientBrush();bgBrush.StartPoint=newPoint(0.5,0);bgBrush.EndPoint=newPoint(0.5,1);GradientStopCollectionstops=newGradient7、StopCollection();GradientStopstop1=newGradientStop();stop1.Color=Colors.Yellow;stop1.Offset=0.0;stops.Add(stop1);GradientStopstop2=newGradientStop();stop2.Color=Colors.Blue;stop2.Offset=0.75;stops.Add(stop2);GradientStopstop3=newGradientStop();stop3.Color=Colors.Green;stop3.Off
5、"StartPoint="0.5,0"EndPoint="0.5,1">
6、0"Width="120"Margin="112,23,168,217"/>方法二:在后台代码中定义资源字典(ResourceDictionary)ResourceDictionarydict=newResourceDictionary();LinearGradientBrushbgBrush=newLinearGradientBrush();bgBrush.StartPoint=newPoint(0.5,0);bgBrush.EndPoint=newPoint(0.5,1);GradientStopCollectionstops=newGradient
7、StopCollection();GradientStopstop1=newGradientStop();stop1.Color=Colors.Yellow;stop1.Offset=0.0;stops.Add(stop1);GradientStopstop2=newGradientStop();stop2.Color=Colors.Blue;stop2.Offset=0.75;stops.Add(stop2);GradientStopstop3=newGradientStop();stop3.Color=Colors.Green;stop3.Off
此文档下载收益归作者所有