【发布时间】:2019-08-21 13:34:14
【问题描述】:
将 WPF 类库迁移到 UWP 类库后,以下代码抛出错误。 DependencyProperty class 的 PropertyType 属性在 WPF 中工作。我试图从 UWP 中 similar 类的 Dependency properties overview 和 this 在线文章中获得帮助,但有点困惑。
我在这里缺少什么以及如何使它起作用?
代码sn -p [方法第一行出错]:
using Windows.UI.Xaml;
using System.Reflection;
using Windows.UI.Xaml.Documents;
using System.ComponentModel;
....
private static void SetPropertyValue(XmlElement xamlElement, DependencyProperty property, string stringValue)
{
TypeConverter typeConverter TypeDescriptor.GetConverter(property.PropertyType);
try
{
object convertedValue = typeConverter.ConvertFromInvariantString(stringValue);
if (convertedValue != null)
{
xamlElement.SetAttribute(property.Name, stringValue);
}
}
catch(Exception)
{
}
}
错误:
“DependencyProperty”不包含“PropertyType”的定义,并且找不到接受“DependencyProperty”类型的第一个参数的可访问扩展方法“PropertyType”(您是否缺少 using 指令或程序集引用?)
安装的“所有”包的快照:
【问题讨论】:
-
简而言之,UWP 或 .NetStandrad 2.0 不支持 System.Windows.DependencyProperty。所以,你需要寻找其他方法在 UWP 中设置属性值。
标签: c# wpf uwp dependency-properties