Show / Hide Table of Contents

Class DefaultFocusBehavior

Implements a behavior to set the default focused element.

Inheritance
System.Object
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Freezable
System.Windows.Media.Animation.Animatable
Microsoft.Xaml.Behaviors.Behavior
Microsoft.Xaml.Behaviors.Behavior<System.Windows.FrameworkElement>
DefaultFocusBehavior
Implements
System.Windows.Media.Animation.IAnimatable
Microsoft.Xaml.Behaviors.IAttachedObject
Microsoft.Xaml.Behaviors.Behavior<System.Windows.FrameworkElement>.AssociatedObject
Microsoft.Xaml.Behaviors.Behavior.CreateInstanceCore()
Microsoft.Xaml.Behaviors.Behavior.Attach(System.Windows.DependencyObject)
Microsoft.Xaml.Behaviors.Behavior.Detach()
Microsoft.Xaml.Behaviors.Behavior.AssociatedType
Microsoft.Xaml.Behaviors.Behavior.Microsoft.Xaml.Behaviors.IAttachedObject.AssociatedObject
System.Windows.Media.Animation.Animatable.ApplyAnimationClock(System.Windows.DependencyProperty, System.Windows.Media.Animation.AnimationClock)
System.Windows.Media.Animation.Animatable.ApplyAnimationClock(System.Windows.DependencyProperty, System.Windows.Media.Animation.AnimationClock, System.Windows.Media.Animation.HandoffBehavior)
System.Windows.Media.Animation.Animatable.BeginAnimation(System.Windows.DependencyProperty, System.Windows.Media.Animation.AnimationTimeline)
System.Windows.Media.Animation.Animatable.BeginAnimation(System.Windows.DependencyProperty, System.Windows.Media.Animation.AnimationTimeline, System.Windows.Media.Animation.HandoffBehavior)
System.Windows.Media.Animation.Animatable.Clone()
System.Windows.Media.Animation.Animatable.FreezeCore(System.Boolean)
System.Windows.Media.Animation.Animatable.GetAnimationBaseValue(System.Windows.DependencyProperty)
System.Windows.Media.Animation.Animatable.HasAnimatedProperties
System.Windows.Freezable.CloneCore(System.Windows.Freezable)
System.Windows.Freezable.CloneCurrentValue()
System.Windows.Freezable.CloneCurrentValueCore(System.Windows.Freezable)
System.Windows.Freezable.CreateInstance()
System.Windows.Freezable.Freeze()
System.Windows.Freezable.Freeze(System.Windows.Freezable, System.Boolean)
System.Windows.Freezable.GetAsFrozen()
System.Windows.Freezable.GetAsFrozenCore(System.Windows.Freezable)
System.Windows.Freezable.GetCurrentValueAsFrozen()
System.Windows.Freezable.GetCurrentValueAsFrozenCore(System.Windows.Freezable)
System.Windows.Freezable.OnChanged()
System.Windows.Freezable.OnFreezablePropertyChanged(System.Windows.DependencyObject, System.Windows.DependencyObject)
System.Windows.Freezable.OnFreezablePropertyChanged(System.Windows.DependencyObject, System.Windows.DependencyObject, System.Windows.DependencyProperty)
System.Windows.Freezable.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs)
System.Windows.Freezable.ReadPreamble()
System.Windows.Freezable.WritePostscript()
System.Windows.Freezable.WritePreamble()
System.Windows.Freezable.CanFreeze
System.Windows.Freezable.IsFrozen
System.Windows.Freezable.Changed
System.Windows.DependencyObject.ClearValue(System.Windows.DependencyProperty)
System.Windows.DependencyObject.ClearValue(System.Windows.DependencyPropertyKey)
System.Windows.DependencyObject.CoerceValue(System.Windows.DependencyProperty)
System.Windows.DependencyObject.Equals(System.Object)
System.Windows.DependencyObject.GetHashCode()
System.Windows.DependencyObject.GetLocalValueEnumerator()
System.Windows.DependencyObject.GetValue(System.Windows.DependencyProperty)
System.Windows.DependencyObject.InvalidateProperty(System.Windows.DependencyProperty)
System.Windows.DependencyObject.ReadLocalValue(System.Windows.DependencyProperty)
System.Windows.DependencyObject.SetCurrentValue(System.Windows.DependencyProperty, System.Object)
System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty, System.Object)
System.Windows.DependencyObject.SetValue(System.Windows.DependencyPropertyKey, System.Object)
System.Windows.DependencyObject.ShouldSerializeProperty(System.Windows.DependencyProperty)
System.Windows.DependencyObject.DependencyObjectType
System.Windows.DependencyObject.IsSealed
System.Windows.Threading.DispatcherObject.Dispatcher
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Sartorius.SAF.Presentation.Controls.Behaviors
Assembly: Sartorius.SAF.Presentation.Controls.dll
Syntax
public class DefaultFocusBehavior : Behavior<FrameworkElement>, IAnimatable, IAttachedObject
Remarks

You can specifically attach this behavior to the element that should be focused, attach it to a container and set the element that should be focused by setting FocusedElement or attach it to a container without setting FocusedElement. In the latter case the first focusable child is focused. This behavior recognizes the following children as focusable:

  • System.Windows.Controls.TextBox
  • System.Windows.Controls.CheckBox
  • System.Windows.Controls.ComboBox
  • System.Windows.Controls.Button
  • System.Windows.Controls.ListView
  • System.Windows.Controls.TreeView
  • System.Windows.Controls.ListBox
  • System.Windows.Controls.PasswordBox
Examples

This example illustrates how to use the DefaultFocusBehavior to focus the first input control, in this case the WatermarkTextBox.

        <HeaderedContentControl xmlns:SAF="http://www.sartorius.com/SAF"
                            xmlns:b="http://schemas.microsoft.com/xaml/behaviors">
        <b:Interaction.Behaviors>
            <SAF:DefaultFocusBehavior />
        </b:Interaction.Behaviors>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="20" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"
                               MinHeight="28" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <SAF:Caption Grid.Row="0"
                         Grid.Column="0"
                         Style="{DynamicResource SAF_ContentBoxCaption}"
                         Text="Name" />

            <!-- This element gets the focus by default. -->
            <SAF:WatermarkTextBox Grid.Row="0"
                                  Grid.Column="2"
                                  Watermark="Max Mustermann"
                                  Style="{SAF:Style WatermarkTextBoxSingleLine}"
                                  Text="{Binding Name, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />

            <SAF:Caption Grid.Row="1"
                         Grid.Column="0"
                         Style="{DynamicResource SAF_ContentBoxCaption}"
                         Text="Description" />
            <TextBox Grid.Row="1"
                     Grid.Column="2"
                     Style="{SAF:Style TextBoxMultiLine}"
                     Text="{Binding Description, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
        </Grid>
    </HeaderedContentControl>

This example illustrates how to use the DefaultFocusBehavior to focus a specific control by setting FocusedElement.

        <HeaderedContentControl xmlns:SAF="http://www.sartorius.com/SAF"
                            xmlns:b="http://schemas.microsoft.com/xaml/behaviors">
        <b:Interaction.Behaviors>
            <SAF:DefaultFocusBehavior FocusedElement="{Binding ElementName=DescriptionTextBox}" />
        </b:Interaction.Behaviors>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="20" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"
                               MinHeight="28" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <SAF:Caption Grid.Row="0"
                         Grid.Column="0"
                         Style="{DynamicResource SAF_ContentBoxCaption}"
                         Text="Name" />


            <SAF:WatermarkTextBox Grid.Row="0"
                                  Grid.Column="2"
                                  Watermark="Max Mustermann"
                                  Style="{SAF:Style WatermarkTextBoxSingleLine}"
                                  Text="{Binding Name, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />

            <SAF:Caption Grid.Row="1"
                         Grid.Column="0"
                         Style="{DynamicResource SAF_ContentBoxCaption}"
                         Text="Description" />
            <!-- This element gets the focus as it is defined by the FocusedElement property. -->
            <TextBox x:Name="DescriptionTextBox"
                     Grid.Row="1"
                     Grid.Column="2"
                     Style="{SAF:Style TextBoxMultiLine}"
                     Text="{Binding Description, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
        </Grid>
    </HeaderedContentControl>

This example illustrates how to use the DefaultFocusBehavior to focus a specific control.

        <HeaderedContentControl xmlns:SAF="http://www.sartorius.com/SAF"
                            xmlns:b="http://schemas.microsoft.com/xaml/behaviors">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="20" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"
                               MinHeight="28" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <SAF:Caption Grid.Row="0"
                         Grid.Column="0"
                         Style="{DynamicResource SAF_ContentBoxCaption}"
                         Text="Name" />


            <SAF:WatermarkTextBox Grid.Row="0"
                                  Grid.Column="2"
                                  Watermark="Max Mustermann"
                                  Style="{SAF:Style WatermarkTextBoxSingleLine}"
                                  Text="{Binding Name, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />

            <SAF:Caption Grid.Row="1"
                         Grid.Column="0"
                         Style="{DynamicResource SAF_ContentBoxCaption}"
                         Text="Description" />
            <!-- This element gets the focus as it is defined by the FocusedElement property. -->
            <TextBox Grid.Row="1"
                     Grid.Column="2"
                     Style="{SAF:Style TextBoxMultiLine}"
                     Text="{Binding Description, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}">
                <b:Interaction.Behaviors>
                    <SAF:DefaultFocusBehavior />
                </b:Interaction.Behaviors>
            </TextBox>
        </Grid>
    </HeaderedContentControl>

Fields

View Source

FocusedElementProperty

Identifies the System.Windows.DependencyProperty for the FocusedElement property.

Declaration
public static readonly DependencyProperty FocusedElementProperty
Field Value
Type Description
System.Windows.DependencyProperty

Properties

View Source

FocusedElement

Gets or sets the element that should be focused.

Declaration
public FrameworkElement FocusedElement { get; set; }
Property Value
Type Description
System.Windows.FrameworkElement

The element that should be focused.

Methods

View Source

IsFocusableInputElement(FrameworkElement)

Checks whether the given element is focusable.

Declaration
protected virtual bool IsFocusableInputElement(FrameworkElement element)
Parameters
Type Name Description
System.Windows.FrameworkElement element

The System.Windows.FrameworkElement

Returns
Type Description
System.Boolean

True if the element is focusable, otherwise false.

View Source

OnAttached()

Called after the behavior is attached to an AssociatedObject.

Declaration
protected override void OnAttached()
Overrides
Microsoft.Xaml.Behaviors.Behavior.OnAttached()
Remarks

Override this to hook up functionality to the AssociatedObject.

View Source

OnDetaching()

Called when the behavior is being detached from its AssociatedObject, but before it has actually occurred.

Declaration
protected override void OnDetaching()
Overrides
Microsoft.Xaml.Behaviors.Behavior.OnDetaching()
Remarks

Override this to unhook functionality from the AssociatedObject.

View Source

OnLoaded(Object, EventArgs)

Called when the Microsoft.Xaml.Behaviors.Behavior.AssociatedObject is loaded.

Declaration
protected virtual void OnLoaded(object sender, EventArgs args)
Parameters
Type Name Description
System.Object sender

The sender.

System.EventArgs args

The System.EventArgs.

Implements

System.Windows.Media.Animation.IAnimatable
Microsoft.Xaml.Behaviors.IAttachedObject

Extension Methods

CollectionExtensions.AddRange<T, TCollection>(TCollection, IEnumerable<T>)
SerializableObjectCloneExtension.Clone<T>(T)
DependencyObjectExtensions.GetContainer(DependencyObject)
DependencyObjectExtensions.SetContainer(DependencyObject, CompositionContainer)
DependencyObjectExtensions.FindAncestor<T>(DependencyObject)
DependencyObjectExtensions.FindFirstChildByType<T>(DependencyObject)
DependencyObjectExtensions.FindLogicalAncestor<T>(DependencyObject)
DependencyObjectExtensions.GetChildsByType<T>(DependencyObject, List<T>)
DependencyObjectExtensions.GetChildrenByType<T>(DependencyObject)
DependencyObjectExtensions.XamlClone<T>(T)
  • View Source
Back to top Generated by DocFX