mrfangzheng

Hope and fear are useless. Be confident, and always be prepared for the worst.
  首页  :: 新随笔  :: 联系 :: 管理

WPF学习计划-Resource

Posted on 2009-01-12 21:06  mrfangzheng  阅读(256)  评论(0编辑  收藏  举报

概述

http://msdn.microsoft.com/en-us/library/ms750613.aspx

需要重用的对象都可以定义成资源, 比如Style, Template, Brush等.

每个FrameworkElement或者FrameworkContentElement元素都有Resources(ResourceDictionary类型)属性.

一个资源一般有一个key, 比如: <SolidColorBrush x:key="MyBrush" Color="Red" .../>

使用资源时, 资源使用者通过{StaticResource XXX}来调用资源, 比如:<Button Background="{StaticResource MyBrush}"/>

 

StaticResource和DynamicResource

???

 

在代码中使用Resource

Window win = ...;

btn.Background = (Brush)win.FindResource("MyBrush");