Behaviors
In the Silverlight version of TT.UIA there are seperate Behaviors for all Adorners. The WPF version of this is planned for the next release.
The following Behaviors wraps the TT.UIA Adorners (see Adorner documentation for a detailed description):
- CueBannerBehavior
- EditContextMenuBehavior
- EditorToolbarBehavior
- EditTrackerBehavior
- ElementTrackerBehavior
- FieldDescriptionBehavior
- HighlightOnFocusBehavior
- RequiredBahavior
- SmartTagBehavior
Beyond that, TT.UIA includes the following Behaviors (for WPF and Silverlight):
Open File Behavior
The
Open File Behavior shows a file open dialog and outputs the selected file to target element. It derives from
Behavior<Control> and can be assigned via the
Interaction.Behaviors attached property.
Declaration:
<CheckBox x:Name="busyCheckBox" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:behaviors="clr-namespace:Thinktecture.UIAnnotations.Behaviors; assembly=Thinktecture.UIAnnotations">
<i:Interaction.Behaviors>
<behaviors:BusyBehavior IsBusy="{Binding ElementName=busyCheckBox, Path=IsChecked}" />
</i:Interaction.Behaviors>
</CheckBox>
Result:
Open File Behavior
The
Open File Behavior shows a file open dialog and outputs the selected file to target element. It derives from
TargetedTriggerAction<UIElement> and can be assigned via the
Interaction.Triggers attached property.
Declaration:
...
<Button xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:behaviors="clr-namespace:Thinktecture.UIAnnotations.Behaviors; assembly=Thinktecture.UIAnnotations">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<!--shows the file open dialog and outputs the selected file to a textbox-->
<behaviors:OpenFileBehavior
TargetName="imageTextBox"
DialogTitle="Select an image..."
Filter="PNG Files|*.png" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<TextBox x:Name="imageTextBox" />
...
Result:
Focus Behavior
The
Focus Behavior colors the background of the focused element with the given brush. It derives from
Behavior<Control> and can be assigned via the
Interaction.Behaviors attached property.
Declaration:
<TextBox xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:behaviors="clr-namespace:Thinktecture.UIAnnotations.Behaviors; assembly=Thinktecture.UIAnnotations">
<i:Interaction.Behaviors>
<behaviors:FocusBehavior HighlightBrush="Yellow" />
</i:Interaction.Behaviors>
</TextBox>
Result:
CueBannerAdornerFactoryBehavior
CueBannerAdornerFactoryBehavior is a proxy class that wraps the
CueBanner Adorner as an
Expression Blend Behavior using the base class
Thinktecture.UIAnnotations.Behaviors.AdornerFactoryBehavior. It can be assigned via the CueBannerAdornerFactoryBehavior.CueBannerText_ attached property.
Declaration:
<TextBox xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:behaviors="clr-namespace:Thinktecture.UIAnnotations.Behaviors; assembly=Thinktecture.UIAnnotations">
<i:Interaction.Behaviors>
<behaviors:CueBannerAdornerFactoryBehavior CueBannerText="Enter your name!" />
</i:Interaction.Behaviors>
</TextBox>
Result:
Dialog Button Behavior
The
Dialog Button Behavior controls the style and behavior of dialog buttons. It changes the
IsDefault or
IsCancel property of the button, closes the dialog if the
Click event is raised (via mouse or
esc/
enter key press), and set the
DialogResult property to a proper value. It derives from
Behavior<Button> and can be assigned via the
Interaction.Behaviors attached property. The type of the dialog button can be set via the
ButtonType property.
Declaration:
<Button xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:behaviors="clr-namespace:Thinktecture.UIAnnotations.Behaviors; assembly=Thinktecture.UIAnnotations">
<i:Interaction.Behaviors>
<behaviors:DialogButtonBehavior ButtonType="Ok" />
</i:Interaction.Behaviors>
</Button>
BehaviorFactory
The
BehaviorFactory is a class that you can use, if you want to assign a behavior via style. This is because you can't declare behaviors and triggers directly in a style.
Declaration
<Window xmlns:behaviors="clr-namespace:Thinktecture.UIAnnotations.Behaviors;assembly=Thinktecture.UIAnnotations" ...>
<Window.Resources>
<Style TargetType="TextBox">
<!--assign behavior in a style via BehaviorFactory-->
<Setter Property="behaviors:BehaviorFactory.BehaviorTypeName" Value="Thinktecture.UIAnnotations.Behaviors.FocusBehavior" />
</Style>
</Window.Resources>
...
</Window>
If you want to override the assignment of behavior via style you can use the
BehaviorFactory.DetachBehaviorTypeName attached property.
<TextBox
behaviors:BehaviorFactory.DetachBehaviorTypeName="Thinktecture.UIAnnotations.Behaviors.FocusBehavior" />
If you want to declare
TriggerAction or
TargetedTriggerAction in a style, use the classes
TriggerActionFactory and
TargetedTriggerActionFactory.
Command Behavior
With the
Command Behavior you can assign a Command to every event (routed or normal event) of a control. In addition you can control which property should be changed if the command state changes.
The
CommandBehavior class derives from
TriggerAction<Control> and can be assigned via the
Interaction.Triggers attached property.
Declaration
<Button x:Name="okButton" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:behaviors="clr-namespace:Thinktecture.UIAnnotations.Behaviors; assembly=Thinktecture.UIAnnotations">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<behaviors:CommandBehavior
Command="{Binding OkCommand}"
PropertyName="Visiblity"
CanExecutePropertyValue="Visible"
CanNotExecutePropertyValue="Collapsed" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
If the state of the command affects the control properties
IsEnabled or
Visibility, you can use a shotcut via the
CommandAction property and set it to
Hide or
Disable.
<Button x:Name="okButton" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:behaviors="clr-namespace:Thinktecture.UIAnnotations.Behaviors; assembly=Thinktecture.UIAnnotations">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<behaviors:CommandBehavior
Command="{Binding OkCommand}"
CommandAction="Hide" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
If you need a converter to convert from bool to the given property type, you can set the properties
Converter and
ConverterParameter.