Grid.FindName和Grid.Children [] [英] Grid.FindName and Grid.Children[]
问题描述
我的以下代码遇到了一个小问题.
我的网格"poolTable"包含一个作为子级的网格"poolBall".
而
网格eobj1 =(Grid)this.poolTable.Children [0];
返回正确的innerGrid,
网格eobj1 =(Grid)this.innerPoolTable.FindName("poolBall");
返回NULL!
知道为什么会这样吗?
Hi,
I''m facing a small issue with the following code.
My Grid "poolTable" Contains a Grid "poolBall" as a child.
While
Grid eobj1 = (Grid)this.poolTable.Children[0];
returns the correct innerGrid,
Grid eobj1 = (Grid)this.innerPoolTable.FindName("poolBall");
returns NULL!
Any idea why this happens so?
推荐答案
尝试一下:
Try this:
Grid eobj1 = (Grid)(LogicalTreeHelper.FindLogicalNode(this.poolTable, "poolBall"));
FindName
方法由于其明显的脆弱性而被普遍鄙视.我敢肯定有一些关于它的使用的规则,但是有时候最好是接受这一方面,并找到另一种做某事的方法. :)
我确定有些Google搜索会在这个问题上找到一些东西.
您还可以更改poolBall
的访问级别,并以这种方式获取它:
The FindName
method is universally despised due to its apparent flakiness. I''m sure there are rules regarding its use, but sometimes it''s better to just accept that aspect, and find another way to do something. :)
I''m sure some googling will find something on the subject.
You could also change the access level of poolBall
, and just get it this way:
this.poolTable.pooolBall
...但是通常对此不屑一顾.
...but that''s generally frowned-upon.
这篇关于Grid.FindName和Grid.Children []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!