Find WPF control by Name

There’s at least two ways to do that:

  • Use the FindName method of the parent container to find the control (but it’ll internally involve looping, like the visualtreehelper)

  • Create a dictionary to store a reference for each control you create

    var controls = new Dictionary<string, FrameworkElement>();
    controls.Add("_marketInfo5", lbl);
    

    Then you can do:

    controls["_marketInfo5"].Tag = timeNow;
    

Leave a Comment