如何从XAML UI控件中获取标签值,而无需事先知道精确的控制类型?
我需要在不知道其精确类型的情况下获取默认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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将控件施加到
Frameworkelement
:You can cast the control to
FrameworkElement
instead: