Hi friends,
One of the useful but sometimes annoying features of WPF is Routed events.
I will describe its problem here.
You have a TabControl and a few TabItems within it. Now, if you add a ConboBox control in any of the TabItem.
Imagine your Tabcontrol's SelectionChanged event getting fired every time user changes selection of ComboBox. Won't it be annoying?
This happens because in WPF, the events bubble up and travel the upward hierarchy of the controls.
Here is one of the easiest solutions for it.
In the event handler code, first check the original source from where this event started, and if did not start from TabControl, just ignore it.
In order to check this, use the following code:
if (e.OriginalSource is TabControl)
{
}
Problem solved :)
One of the useful but sometimes annoying features of WPF is Routed events.
I will describe its problem here.
You have a TabControl and a few TabItems within it. Now, if you add a ConboBox control in any of the TabItem.
Imagine your Tabcontrol's SelectionChanged event getting fired every time user changes selection of ComboBox. Won't it be annoying?
This happens because in WPF, the events bubble up and travel the upward hierarchy of the controls.
Here is one of the easiest solutions for it.
In the event handler code, first check the original source from where this event started, and if did not start from TabControl, just ignore it.
In order to check this, use the following code:
if (e.OriginalSource is TabControl)
{
}
Problem solved :)
1 comment:
Thank you very, very much. I've been struggling through this for the past 2 hours and this little line of code solved everything.
Post a Comment