使用GetValueSource方法获取依赖属性的源
来源:互联网 发布:java怎么做网站 编辑:程序博客网 时间:2024/06/04 18:36
from:
http://wpf.2000things.com/2010/12/05/146-use-getvaluesource-method-to-find-the-source-of-a-dependency-property-value/
It’s often helpful to determine the source of the current value of a dependency property. You can use theDependencyPropertyHelper.GetValueSource method to do this.
In the following example, the source for the value of the Foreground property alternates between the style and the style trigger, based on the value of the IsEnabled property.
<Window.Resources> <Style x:Key="redgreenButton" TargetType="{x:Type Button}"> <Setter Property="Foreground" Value="Green"/> <Style.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Foreground" Value="Red"/> </Trigger> </Style.Triggers> </Style></Window.Resources><StackPanel Orientation="Vertical"> <Button Content="A Button" Height="23" Width="75" Style="{StaticResource redgreenButton}" Name="btnTest"/> <Button Content="Enable/Disable" Height="24" Width="100" Name="btnDisable" Click="btnDisable_Click"/> <Button Content="Display Source" Height="24" Width="100" Name="btnDisplay" Click="btnDisplay_Click"/></StackPanel>
Here’s the code for the Display button’s Click event, which uses GetValueSource to report the base value source.
private void btnDisplay_Click(object sender, RoutedEventArgs e){ ValueSource vs = DependencyPropertyHelper.GetValueSource(btnTest as DependencyObject, Button.ForegroundProperty); MessageBox.Show(string.Format("Source for Foreground property: {0}", vs.BaseValueSource));}
- 使用GetValueSource方法获取依赖属性的源
- WPF 依赖属性的创建与使用
- Java 使用反射获取类、方法、属性上的注释
- [UWP]依赖属性2:使用依赖属性
- [UWP]依赖属性2:使用依赖属性
- WPF 依赖属性使用
- 获取NSAttributedString属性的方法
- 方法、属性的使用
- WPF 自定义控件的依赖属性的绑定方法
- set方法注入依赖属性
- 依赖属性基本注册方法
- 依赖属性的理解
- Silverlight的依赖属性
- WPF注册依赖属性—依赖属性值继承方法
- Linux下获取依赖包而不安装的方法
- 环信依赖包EaseUI获取上下文的方法
- java中获取系统属性的方法
- 获取类中[DisplayName("")]属性的方法
- JSP EL表达式详细引见与JSTL&…
- C:\fakepath\文件路径问题
- response.setHeader()的用法 乱码问题、编码问题
- 在没有Photoshop的年代,NASA这样拼接相片
- Couldn't load libbt_serialport: findLibrary returned null
- 使用GetValueSource方法获取依赖属性的源
- SecureCRT for Mac OS X 6.7.3破解方法
- Android开源介绍-UI组件
- hdu 1045
- 一步一步学cscope
- iOS面试问题
- Android memory leakage
- vs2010 未能将脚本调试器附加到计算机上的进程。已附加了一个调试器
- iOS自定义UIAcionSheet