如何从XAML UI控件中获取标签值,而无需事先知道精确的控制类型?

发布于 2025-02-03 06:31:09 字数 224 浏览 3 评论 0原文

我需要在不知道其精确类型的情况下获取默认XAML控件的标签值。 我尝试过铸造UIELEMENT,尽管对大多数标准属性都有效,但似乎对标签属性不起作用。

if (control is UIElement e)
{
    object tagValue = e.Tag; //Error: UIElement doesn't contain a definition for Tag
}

I need to get the Tag value of a default XAML control without knowing it's precise type.
I have tried casting to UIElement, which although works for most standard properties, doesn't seem to work for the Tag property.

if (control is UIElement e)
{
    object tagValue = e.Tag; //Error: UIElement doesn't contain a definition for Tag
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一身骄傲 2025-02-10 06:31:09

您可以将控件施加到Frameworkelement

    if (control is FrameworkElement e)
    {
        object tagValue = e.Tag;
    }

You can cast the control to FrameworkElement instead:

    if (control is FrameworkElement e)
    {
        object tagValue = e.Tag;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文