本文介绍了字符串的DependencyProperty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将属性名称(以字符串形式)转换为 DependencyProperty
?
How do I convert a property name (in string) to a DependencyProperty
?
我有一组属性名称,其值以字符串和 DependencyObject
表示。现在,我想将这些属性值设置为 DependencyObject
。关于如何实现的任何想法?
I have a set of property names, its values in string and a DependencyObject
. Now I want to set these property values to the DependencyObject
. Any idea on how this can be achieved?
谢谢。
推荐答案
您可以获得使用DependencyPropertyDescriptor.FromName方法,然后从该描述符中获取依赖项属性标识符。
You can get DependencyPropertyDescriptor using DependencyPropertyDescriptor.FromName method and then get dependency property identifier from this descriptor.
var descriptor = DependencyPropertyDescriptor.FromName(
propertyName,
dependencyObject.GetType(),
dependencyObject.GetType());
// now you can set property value with
descriptor.SetValue(dependencyObject, value);
// also, you can use the dependency property itself
var property = descriptor.DependencyProperty;
dependencyObject.SetValue(property, value);
这篇关于字符串的DependencyProperty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!