- 1、本文档共16页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
[13WPF资源
一、什么是资源
通常使用 WPF 资源作为重用通常定义的对象和值的简单方法。例如定义一种可以复用的单色的Brush对象,按钮的背景及矩形的填充颜色均使用此Brush:
1: Window x:Class=WPFResource.WinBasicResource
2: xmlns=/winfx/2006/xaml/presentation
3: xmlns:x=/winfx/2006/xaml
4: Title=Basic Resource Height=200 Width=300
5: Window.Resources
6: SolidColorBrush x:Key=myBrush Color=Gold /
7: /Window.Resources
8: StackPanel
9: Button Margin=5 Content=Sample Button Background={StaticResource myBrush} /
10: Rectangle Margin=5 Width=100 Height=100 Fill={StaticResource myBrush} /
11: /StackPanel
12: /Window
在WPF中资源通常用作“样式”(Style)、样式模板、数据模板等。
二、资源的定义及XAML中引用
资源可以定义在以下几个位置:
应用程序级资源:定义在App.xaml文件中,作为整个应用程序共享的资源存在
在App.xaml文件中定义:
1: Application x:Class=WPFResource.App
2: xmlns=/winfx/2006/xaml/presentation
3: xmlns:x=/winfx/2006/xaml
4: StartupUri=Window1.xaml
5: Application.Resources
6: SolidColorBrush Color=Gold x:Key=myGoldBrush /
7: /Application.Resources
8: /Application
在ApplicationResourceDemo.xaml文件(窗体)中使用App.xaml中定义的Resource
1: Window x:Class=WPFResource.ApplicationResourceDemo
2: xmlns=/winfx/2006/xaml/presentation
3: xmlns:x=/winfx/2006/xaml
4: Title=Application Resource Demo Height=300 Width=300
5: StackPanel
6: Button Margin=5 Background={StaticResource myGoldBrush}Sample Button/Button
7: /StackPanel
8: /Window
窗体级资源:定义在Window或Page中,作为一个窗体或页面共享的资源存在
1: Window x:Class=WPFResource.WindowResourceDemo
2: xmlns=/winfx/2006/xaml/presentation
3: xmlns:x=/winfx/2006/xaml
4: Title=WindowResourceDemo Height=300 Width=300
5: Window.Resources
6: SolidColorBrush x:Key=myRedBrush Color=Red /
7: /Window.Resources
8: StackPanel
9: Button Margin=5 Background={StaticResource myRedBrush}Sample Button/Button
10: /StackPanel
11: /Window
文件级资源:定义在资源字典的XAML文件中,再引用
在Visual Studio的WPF应用程序项目中,添加“资源字典(Resourc
文档评论(0)