包含在一個ItemsControl的控件當我拿到我的ItemsControl
的ItemsSource
,它的視圖模型界的ObservableCollection
回到我到我的用戶控件,但我想我的用戶控件的ObservableCollection
。 我怎樣才能獲得包含在我的ItemsControl
用戶控件?獲取代碼
Q
獲取代碼
3
A
回答
1
首先,你需要調用ItemsControl.ContainerFromElement獲得「根控制」顯示的每個數據項。而且你可以使用VisualTreeHelper遍歷控制。
1
你也可以看看ItemContainerGenerator。你也許可以使用ContainerFromIndex或ContainerFromItem方法將每個元素的容器。
1
您可以使用FindByName根控制的,或經過視覺樹具有這種功能
public static FrameworkElement FindByName(string name, FrameworkElement root)
{
Stack<FrameworkElement> tree = new Stack<FrameworkElement>();
tree.Push(root);
while (tree.Count > 0)
{
FrameworkElement current = tree.Pop();
if (current.Name == name)
return current;
int count = VisualTreeHelper.GetChildrenCount(current);
for (int i = 0; i < count; ++i)
{
DependencyObject child = VisualTreeHelper.GetChild(current, i);
if (child is FrameworkElement)
tree.Push((FrameworkElement)child);
}
}
return null;
}
相關問題
- 1. 獲取代碼
- 2. 獲取代碼
- 3. 獲取代碼
- 4. 獲取源代碼。
- 5. 獲取從代碼
- 6. 獲取源代碼
- 7. 獲取從代碼
- 8. 獲取代碼爲
- 9. 獲取java.lang.NumberFormatException代碼
- 10. Swift:獲取請求獲取源代碼
- 11. 獲取Android的源代碼
- 12. 獲取從API代碼
- 13. CoreData - 獲取代碼swift3
- 14. SymbolSource獲取源代碼
- 15. 獲取iframe源代碼?
- 16. 獲取ISO國家代碼
- 17. 獲取頁面源代碼
- 18. PHP preg_match_all獲取PHP代碼
- 19. 獲取Container.ItemIndex代碼後面
- 20. 無法獲取代碼。
- 21. 獲取代碼隱藏
- 22. 從SVN獲取代碼
- 23. 獲取網頁源代碼
- 24. UIWebView獲取HTML源代碼
- 25. 獲取頁面源代碼
- 26. 獲取部分代碼值
- 27. 獲取LAUNCHER2源代碼?
- 28. 獲取最新源代碼
- 29. 獲取Android源代碼
- 30. 獲取http代碼請求