-1

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
}
Andrew
  • 171
  • 1
  • 7

1 Answers1

1

You can cast the control to FrameworkElement instead:

    if (control is FrameworkElement e)
    {
        object tagValue = e.Tag;
    }
Andrew
  • 171
  • 1
  • 7