Home > Enterprise >  WPF retaining IsFocused status for user control
WPF retaining IsFocused status for user control

Time:03-21

I have a usercontrol(UC), and several of it's implementations on 1 screen. Now, whenever any of them has IsFocused property set to True(it will only stay true for 1 at a time), there are some style effects that will appear for only that specific implementation(some highlighting styles basically). If some other implementation gets focused upon, those styles will only appear for that new one, and will be lost for old one.

Now, on that screen, if I create a completely new button, which has nothing to do with those controls, and if I click on it, the styles are lost for the last focused UC. I want to retain the styles for the UCs specifically, so that, if a UC is already focused and showing the styles, those should stay as long as some other UC of that type is not clicked upon. Like clicking on anything other than those UCs shouldn't interfere with the onFocused styles of currently focus UC. Hope it makes sense.

CodePudding user response:

You must create a new focus scope for the context which should have an independent focus management, with the help of the FocusManager:

<MyUserControl FocusManager.IsFocusScope="True" />
  • Related