首页 > 解决方案 > 如何在 WPF 中将属性名称转换为框架元素?

问题描述

这是 C# 中的代码:

 public static FrameworkElement GetFocusedOn(UIElement element)
    {
        return (FrameworkElement)element.GetValue(FocusedOnProperty);
    }

我正在尝试在 VB.NET 中编写它,但它不会转换为 FrameworkElement。有任何想法吗?

标签: c#.netwpfvb.netxaml

解决方案


如果该FocusedOn属性返回 a ,这应该可以工作FrameworkElement

Public Shared Function GetFocusedOn(ByVal element As UIElement) As FrameworkElement
    Return CType(element.GetValue(FocusedOnProperty), FrameworkElement)
End Function

您想使用TryCast 运算符


推荐阅读