使用变量访问WPF元素

时间:2015-12-27 00:21:58

标签: c# wpf variables

我在WPF网格中有许多Grid元素。每个网格都被命名为'DocumentPage1','DocumentPage2','DocumentPage3'等。

如果我想编辑'DocumentPage'+ An'int'Variable,我该怎么办?

这不起作用:

...
int PageToAccess = 2;
"DocumentPage" + PageToAccess.Height = 200; //This does not work
...

1 个答案:

答案 0 :(得分:1)

您可以使用FindName按名称获取对象。

var superCounter = function(str) {
    var counterObj = {};
    counterObj.spaces = 0;
    counterObj.words = str.split(' ').length;
    str.split('').forEach(function(e) {
        if(e === ' ') {
            counterObj.spaces += 1;
        }
    });
    counterObj.chars = str.length;
    return counterObj;
}; 
console.log(superCounter("Count me in"));