Theo
Theo

Reputation: 588

Using Variable To Access WPF Element

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
...

Upvotes: 2

Views: 685

Answers (1)

J3soon
J3soon

Reputation: 3133

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

...
int PageToAccess = 2;
((Control)FindName("DocumentPage" + PageToAccess)).Height = 200;
...

Upvotes: 3

Related Questions