Advertisement
Guest User

lala

a guest
Jan 30th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. Hi jbroun,
  2.  
  3. Windows Presentation Foundation(WPF) is a presentation technology, based on my understanding, the smartest design of WPF is to separate your UI and Data.
  4.  
  5. Your TextBox is just a "Show Data" control.
  6.  
  7. As for your issue, I think you have two way to achieve it.
  8.  
  9. 1) As Reed metioned, you could all the data source which are binded to the TextBox, and then your TextBox will be cleared automatically.
  10.  
  11. 2) You could loop your Visual tree from the root control(Window), if the find the TextBox, you could clear it, about how to loop the VisualTree, you could use VisualTreeHelper, for more details:
  12.  
  13. http://msdn.microsoft.com/en-us/library/system.windows.media.visualtreehelper.aspx
  14.  
  15. I code a test method, you could refer to:
  16.  
  17. void LoopVisualTree(DependencyObject obj)
  18. {
  19. for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
  20. {
  21. if (obj is TextBox)
  22. ((TextBox)obj).Text = null;
  23. LoopVisualTree(VisualTreeHelper.GetChild(obj, i));
  24. }
  25. }
  26. Use this method could clear all the TextBox.
  27.  
  28.  
  29.  
  30. Best regards,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement