wpf - How can I style a custom control based on if any of its children have focus? -


we have custom canvas has specialized nodes behave lot standard mdi application's windows. desired behavior if of child controls of "window" have focus, "window" said active.

now isfocused property doesn't seem cascade, meaning if child control has focus, it's container not set 'focused' can't use that. same reason, can't set isfocused property on container believe steal child.

my thought create new dp called haschildwithfocus or that, in code-behind, listen bubbled events , set flag. not sure that's best way go. (we may implement combination attached property/attached behavior kinda thing.)

but of course better if ask control 'hey... or of children have focus?'

so can you?

you can use uielement.iskeyboardfocuswithin directly this:

<grid>     <grid.resources>         <style x:key="panelstyle" targettype="border">             <setter property="borderbrush" value="palegoldenrod"/>             <style.triggers>                 <trigger property="iskeyboardfocuswithin" value="true">                     <setter property="borderbrush" value="palegreen"/>                 </trigger>             </style.triggers>         </style>     </grid.resources>     <uniformgrid columns="2">         <border borderthickness="10" style="{staticresource panelstyle}">             <stackpanel>                 <textbox text="textbox1"/>                 <textbox text="textbox2"/>             </stackpanel>         </border>         <border borderthickness="10" style="{staticresource panelstyle}">             <stackpanel>                 <textbox text="textbox3"/>                 <textbox text="textbox4"/>             </stackpanel>         </border>     </uniformgrid> </grid> 

in example border contains element keyboard focus styled different border brush.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -