Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
swdev:dotnet:focus_scopes [2010/12/09 10:21]
smayr
swdev:dotnet:focus_scopes [2010/12/09 10:29] (current)
smayr [Logical Focus]
Line 1: Line 1:
 == Focus Scopes == == Focus Scopes ==
  
-Sometimes, controls need to be grouped into focus scopes so that there is always a focused control in that group, irrespective of the actual keyboard focus (there can only be one keyboard focused control in an application at any given time).+Sometimes, controls need to be grouped into focus scopes so that there is always a logically focused control in that group, irrespective of the actual keyboard focus (there can only be one keyboard focused control in an application at any given time).
  
-To create a focus scope, make a parent control to be include ''FocusManager.IsFocusScope="True"'':+=== Logical Focus === 
 +To create a logical focus scope, make a parent control to be include ''FocusManager.IsFocusScope="True"'':
 <code xml> <code xml>
 <StackPanel Name="pnlsideButtonsMain" FocusManager.IsFocusScope="True"> <StackPanel Name="pnlsideButtonsMain" FocusManager.IsFocusScope="True">
Line 18: Line 19:
 </code> </code>
  
-To set the focus in a control:+To set the focus in a control (eg. a button, in this case called ''btnReports''):
 <code csharp> <code csharp>
 // Sets the focused element in focus scope pnlsideButtonsMain // Sets the focused element in focus scope pnlsideButtonsMain
Line 25: Line 26:
 </code> </code>
  
-To style a control to show focus:+=== Focus Styles === 
 + 
 +To style a control to show keyboard focus and logical focus:
 <code xml> <code xml>
 <Style x:Key="ButtonSimpleStyles" TargetType="{x:Type Button}"> <Style x:Key="ButtonSimpleStyles" TargetType="{x:Type Button}">
Line 45: Line 48:
                 </Border>                 </Border>
                 <ControlTemplate.Triggers>                 <ControlTemplate.Triggers>
 +                    <!--Keyboard focus-->
                     <Trigger Property="IsKeyboardFocused" Value="true">                     <Trigger Property="IsKeyboardFocused" Value="true">
                         <Setter TargetName="Border" Property="BorderBrush" Value="SteelBlue" />                         <Setter TargetName="Border" Property="BorderBrush" Value="SteelBlue" />
Line 50: Line 54:
                         <Setter Property="Foreground" Value="White" />                         <Setter Property="Foreground" Value="White" />
                     </Trigger>                     </Trigger>
 +                    <!--Logical focus (within focus scope)-->
                     <Trigger Property="IsFocused" Value="true">                     <Trigger Property="IsFocused" Value="true">
                         <Setter TargetName="Border" Property="BorderBrush" Value="SteelBlue" />                         <Setter TargetName="Border" Property="BorderBrush" Value="SteelBlue" />
Line 62: Line 67:
 </Style>                         </Style>                        
 </code> </code>
 +
 +== References ==
 +  * [[http://msdn.microsoft.com/en-us/library/aa969768.aspx|MSDN: Focus Overview]]