In a UI I\'m building, I want to adorn a panel whenever one of the controls in the panel has the focus. So I handle the IsKeyboardFocusWithinChanged
event, and add
You need to invoke the dispatcher on the panel. Add a handler to the TextBox SizeChanged event:
private void myTextBox_SizeChanged(object sender, SizeChangedEventArgs e)
{
panel.Dispatcher.Invoke((Action)(() =>
{
if (panel.IsKeyboardFocusWithin)
{
// remove and add adorner to reset
myAdornerLayer.Remove(myAdorner);
myAdornerLayer.Add(myAdorner);
}
}), DispatcherPriority.Render, null);
}
This basically comes from this post: http://geekswithblogs.net/NewThingsILearned/archive/2008/08/25/refresh--update-wpf-controls.aspx