2

I have a number of Grid elements in a WPF Grid. Each Grid is named as 'DocumentPage1', 'DocumentPage2','DocumentPage3', etc.

If I wish to edit 'DocumentPage' + An'int'Variable, what am I to do?

This does not work:

...
int PageToAccess = 2;
"DocumentPage" + PageToAccess.Height = 200; //This does not work
...
4
  • 1
    Put them in an array. Commented Dec 27, 2015 at 0:25
  • Just asking, put what in an array? Any hint would be useful. Thank you! Commented Dec 27, 2015 at 1:51
  • Put the controls in an array (in your constructor). You can them access them by index from the array. Commented Dec 27, 2015 at 1:51
  • Use VisualTreeHelper.. like the answer from this stackoverflow.com/questions/636383/… Commented Dec 27, 2015 at 2:22

1 Answer 1

3

You can use FindName to get a object by its name.

...
int PageToAccess = 2;
((Control)FindName("DocumentPage" + PageToAccess)).Height = 200;
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.