WPF資源維持方法介紹
作者:佚名
WPF資源數量繁多,如何更好的組織這些資源,維持自己的資源利用是一個非常重要的操作。在這里我們就為大家介紹有關WPF資源維持的具體方法。
通過對WPF的應用,開發人員會發現,在一個程序中WPF資源的存在數量是非常驚人的。那么,如何組織我們的WPF資源。在WPF中可以有很多種組織資源的方式。#t#
每個元素維持自己的WPF資源。擁有Resources屬性的對象有很多種類型,比如Application、Window、Page、Style、FrameworkTemplate、FrameworkElement、FrameworkContentElement等。在這種模式種每種元素維持自己所需要的資源,而不顧忌資源是否可以共享,比如兩個Button:
- < Button x:Name="btn1"
- Content="button 1"
- Foreground="{Dynamic
Resource redBrush}"> - < Button.Resources>
- < SolidColorBrush
x:Key="redBrush" Color="Red"/> - < /Button.Resources>
- < /Button>
- < Button x:Name="btn2"
- Content="button 2"
- Foreground="{Dynamic
Resource redBrush}"> - < Button.Resources>
- < SolidColorBrush
x:Key="redBrush" Color="Red"/> - < /Button.Resources>
- < /Button>
這造成的問題是,WPF資源不能共享而重復創建一些相同的資源影響效率。
責任編輯:曹凱
來源:
博客園