I have an application where I have a custom UserControl inside a TabControl. Every so often the whole app needs to refresh it’s data. To handle it, I’m doing the following in the code-behind.
public void OnDataReloaded(object a)
{
WindowManager.GraphControl = new GraphControl();
GraphTab.Content = WindowManager.GraphControl;
graphloaded = true;
}
GraphTab is an instance of TabItem in my TabControl. WindowManager is a static class that handles references to currently active User Controls.
On my UserControl, I have added an event handler: KeyDown=”MyGraphControl_KeyDown_1″ as a property to the UserControl.
After I execute the code above, everything works as expected. My TabControl loads the new UserControl, however keydown events aren’t being captured anymore. Any idea why that might be the case?
Thanks!
Im not 100% sure but my best guess is that because its a new instance of a GraphControl – the Events would have been destroyed or are still in linked to the old instance of the control in Memory.
Before you give it a new instance, make sure you un subscribe to the events and also try re pointing the event handlers to your methods.
Hope that helps!
ste.