2016-02-26 36 views
0

我在所述網格內動態創建了一系列gridstextblocks。不過,我無法使用.FindName來調用我需要的textblock。我的控制層次結構是這樣的:WPF查找動態創建的網格及其子節點

首頁 - > ScrollViewer中 - >格 - >動態創建網格 - > 動態創建的控件

這是我當前如何試圖打電話給他們,任何我嘗試的其他方式仍然沒有得到我的地方

Dim grd As Object = FindName("GridLine" + Ri.ToString()) 
Dim tempgrd As Grid = DirectCast(grd, Grid) 

Dim txtID As Object = tempgrd.FindName("txtIDGrid" + Ri.ToString()) 
Dim tempID As TextBlock = DirectCast(txtID, TextBlock) 

sqlID = tempID.Name 
+1

你有沒有看過mvvm? – blindmeis

+0

我其實沒有。對WPF環境來說還是比較新的。你能給我提供更多的信息嗎?爲什麼這會解決我的問題? –

回答

1

如果其他人正在尋找類似的答案,我最終解決了它。您必須確保您正在創建的控件是RegisterName,以確保您可以在運行時調用它。