c# - manage focus in wpf -



c# - manage focus in wpf -

in wpf app , have 2 views , 2 viewmodels, when first viewmodel binded contentcontrol, first view loaded according viewmodel , 1 of buttons on first view has focused, when sec viewmodel binded contentcontrol,the sec view loaded according sec view, when , show first viewmodel , view, want focus old button has focused,

some things bellow:

public static iinputelement focusedelement; public ucmainmenu() { initializecomponent(); } private void usercontrol_loaded(object sender, routedeventargs e) { keyboard.focus( focusedelement); } private void usercontrol_unloaded(object sender, routedeventargs e) { focusedelement = keyboard.focusedelement; }

create bool isfocused property in view models , info bind uielement.isfocused property of relevant controls:

<button isfocused="{binding isfocused}" ... />

then whenever want focus either 1 of them, set isfocused property true in relevant view model:

isfocused = true;

note if true, may need first set false , true work.

c# wpf

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -