WPF - Clear all textboxes in All TabItem of TabControl
WPF - Clear all textboxes in All TabItem of TabControl
In WPF, I use tabcontrol have tabitems to create new Dynamic content. I have button Reset to clear all textboxes in All TabItems. My code is working with tab focus. But, When I click the other tab and click again old tab, The content show again. Please help me so that I can clear all textboxes in all tabItems
My Code here:
private void ClearControls(DependencyObject root)
System.Windows.Controls.TabControl controls = new System.Windows.Controls.TabControl();
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++)
var control = VisualTreeHelper.GetChild(root, i);
if (control is System.Windows.Controls.TextBox)
(control as System.Windows.Controls.TextBox).Text = String.Empty;
else if (VisualTreeHelper.GetChildrenCount(control) > 0)
ClearControls(control);
private void BtnResetTurnbyTurn_Click(object sender, RoutedEventArgs e)
ClearControls(this);
1 Answer
1
Don't waste your time with tree visualizer
Design your ui in a separately usercontrol and give a name then from
Then head to your main window and give the area that is supposed to display the ui a name or just declare a grid and give it a name
Now head to your tabs and double click the one that is suppoused to show the ui you want and from the code just write the following
Just to clarify the names
I have my separately designd ui in a file called pages and it's name is myui and my usercontrol tag is name child
My viewing area is filled with a grid named
Mainview
I have double clicked the required tab and it drove me to the cs file inside the click event
My code is
` pages.myui mu =new pages.myui();
Mainview.Children.Clear();
Mainview.Cildren.Add(mu.child);`
It might be the most basic way to accomplish the mission but believe me it is a life saver
Comment for any question
I hope i have helped you
Yusuf naeem
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.