Wednesday, September 14, 2011

Myth Self Note 7: C# WPF - clear usercontrol


Situation:
i - stkBody children name 'usercontrolA' should be remove when btnStart is click. And 'usercontrolA' will be replace with other usercontrol
ii - usercontrolA : stkMain, stkLeft, stkRight, btnStart

Problem:
To clear the stkBody children (in this case is usercontrolA), use stkBody.Children.clear();
But we can't access stkBody within the 'usercontrolA' body itself.

Solution:
When declaring and adding usercontrolA to the stkBody children, declare btnStart

usercontrolA usercontrolA = new usercontrolA();
stkBody.Children.Add(usercontrolA);
usercontrolA.btnStart.Click += new RoutedEventHandler(btnStart_Click);

void btnScan_Click(object sender, RoutedEventArgs e)
{
stkBody.Children.Clear();
}

themythstoodstill: note for my future self; if don't understand,you should recall back 14/9/11..btnScan, clear parent stack

Source : Link

0 comments: