VB2015 Programming Question Accessing Object Properties

Glenn Currie 21 Reputation points
2020-05-15T15:50:18.68+00:00

I want to access an objects properties using a string and not the specific object name. Example: Radio Button name is rdb11. Set a string variable strObject = "rdb11" then attempt to change the objects properties using the string strObject.Checked produces a build error.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,671 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lloyd Sheen 1,376 Reputation points
    2020-05-15T16:11:54.33+00:00

    What you are asking is really not the way to do things in WPF. Use MVVM to set properties (that are going to change). You end up with an object (ViewModel) that has properties that when changed will change the properties of the control in the UI that the property is bound to.

    If you are bound to do what you ask you need to investigate reflection.

    It seems that you want to create a line of code in a string and then execute it. To do this you should look into CodeDom.

    I think what you are trying will in the long run not do you any good and the time to implement something like what you ask will be long and difficult


0 additional answers

Sort by: Most helpful