Show / Hide Table of Contents

Class DefaultFocusBehavior

Implements a behavior to set the default focused element.

Inheritance
object
DispatcherObject
DependencyObject
Freezable
Animatable
Behavior
Behavior<FrameworkElement>
DefaultFocusBehavior
Implements
IAnimatable
IAttachedObject
Behavior<FrameworkElement>.AssociatedObject
Behavior.CreateInstanceCore()
Behavior.Attach(DependencyObject)
Behavior.Detach()
Behavior.AssociatedType
Animatable.ApplyAnimationClock(DependencyProperty, AnimationClock)
Animatable.ApplyAnimationClock(DependencyProperty, AnimationClock, HandoffBehavior)
Animatable.BeginAnimation(DependencyProperty, AnimationTimeline)
Animatable.BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior)
Animatable.Clone()
Animatable.FreezeCore(bool)
Animatable.GetAnimationBaseValue(DependencyProperty)
Animatable.HasAnimatedProperties
Freezable.CloneCore(Freezable)
Freezable.CloneCurrentValue()
Freezable.CloneCurrentValueCore(Freezable)
Freezable.CreateInstance()
Freezable.Freeze()
Freezable.Freeze(Freezable, bool)
Freezable.GetAsFrozen()
Freezable.GetAsFrozenCore(Freezable)
Freezable.GetCurrentValueAsFrozen()
Freezable.GetCurrentValueAsFrozenCore(Freezable)
Freezable.OnChanged()
Freezable.OnFreezablePropertyChanged(DependencyObject, DependencyObject)
Freezable.OnFreezablePropertyChanged(DependencyObject, DependencyObject, DependencyProperty)
Freezable.OnPropertyChanged(DependencyPropertyChangedEventArgs)
Freezable.ReadPreamble()
Freezable.WritePostscript()
Freezable.WritePreamble()
Freezable.CanFreeze
Freezable.IsFrozen
Freezable.Changed
DependencyObject.ClearValue(DependencyProperty)
DependencyObject.ClearValue(DependencyPropertyKey)
DependencyObject.CoerceValue(DependencyProperty)
DependencyObject.Equals(object)
DependencyObject.GetHashCode()
DependencyObject.GetLocalValueEnumerator()
DependencyObject.GetValue(DependencyProperty)
DependencyObject.InvalidateProperty(DependencyProperty)
DependencyObject.ReadLocalValue(DependencyProperty)
DependencyObject.SetCurrentValue(DependencyProperty, object)
DependencyObject.SetValue(DependencyProperty, object)
DependencyObject.SetValue(DependencyPropertyKey, object)
DependencyObject.ShouldSerializeProperty(DependencyProperty)
DependencyObject.DependencyObjectType
DependencyObject.IsSealed
DispatcherObject.Dispatcher
object.Equals(object, object)
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
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:

  • TextBox
  • CheckBox
  • ComboBox
  • Button
  • ListView
  • TreeView
  • ListBox
  • 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 DependencyProperty for the FocusedElement property.

Declaration
public static readonly DependencyProperty FocusedElementProperty
Field Value
Type Description
DependencyProperty

Properties

View Source

FocusedElement

Gets or sets the element that should be focused.

Declaration
public FrameworkElement FocusedElement { get; set; }
Property Value
Type Description
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
FrameworkElement element

The FrameworkElement

Returns
Type Description
bool

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
object sender

The sender.

EventArgs args

The EventArgs.

Implements

IAnimatable
Microsoft.Xaml.Behaviors.IAttachedObject

Extension Methods

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