using-wpf-behaviors-triggers — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited using-wpf-behaviors-triggers (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.*" /><Window xmlns:b="http://schemas.microsoft.com/xaml/behaviors">Executes actions when events occur.
<Button Content="Click Me">
<b:Interaction.Triggers>
<b:EventTrigger EventName="Click">
<b:InvokeCommandAction Command="{Binding ClickCommand}"/>
</b:EventTrigger>
</b:Interaction.Triggers>
</Button><ListBox>
<b:Interaction.Triggers>
<b:EventTrigger EventName="SelectionChanged">
<b:InvokeCommandAction Command="{Binding SelectionChangedCommand}"
PassEventArgsToCommand="True"/>
</b:EventTrigger>
</b:Interaction.Triggers>
</ListBox><Button Content="Toggle Visibility">
<b:Interaction.Triggers>
<b:EventTrigger EventName="Click">
<b:ChangePropertyAction TargetName="MyPanel"
PropertyName="Visibility"
Value="Collapsed"/>
</b:EventTrigger>
</b:Interaction.Triggers>
</Button>
<StackPanel x:Name="MyPanel"/>Executes actions based on data conditions.
<TextBlock Text="{Binding Status}">
<b:Interaction.Triggers>
<b:DataTrigger Binding="{Binding IsLoading}" Value="True">
<b:ChangePropertyAction PropertyName="Text" Value="Loading..."/>
<b:ChangePropertyAction PropertyName="Foreground" Value="Gray"/>
</b:DataTrigger>
<b:DataTrigger Binding="{Binding HasError}" Value="True">
<b:ChangePropertyAction PropertyName="Foreground" Value="Red"/>
</b:DataTrigger>
</b:Interaction.Triggers>
</TextBlock>Encapsulates reusable behaviors.
public sealed class FocusOnLoadBehavior : Behavior<UIElement>
{
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.Loaded += OnLoaded;
}
protected override void OnDetaching()
{
base.OnDetaching();
AssociatedObject.Loaded -= OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
AssociatedObject.Focus();
}
}<TextBox>
<b:Interaction.Behaviors>
<local:FocusOnLoadBehavior/>
</b:Interaction.Behaviors>
</TextBox>public sealed class SelectAllOnFocusBehavior : Behavior<TextBox>
{
public static readonly DependencyProperty IsEnabledProperty =
DependencyProperty.Register(
nameof(IsEnabled),
typeof(bool),
typeof(SelectAllOnFocusBehavior),
new PropertyMetadata(true));
public bool IsEnabled
{
get => (bool)GetValue(IsEnabledProperty);
set => SetValue(IsEnabledProperty, value);
}
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.GotFocus += OnGotFocus;
}
protected override void OnDetaching()
{
base.OnDetaching();
AssociatedObject.GotFocus -= OnGotFocus;
}
private void OnGotFocus(object sender, RoutedEventArgs e)
{
if (IsEnabled)
{
AssociatedObject.SelectAll();
}
}
}<TextBox Text="Select me on focus">
<b:Interaction.Behaviors>
<local:SelectAllOnFocusBehavior IsEnabled="{Binding IsSelectAllEnabled}"/>
</b:Interaction.Behaviors>
</TextBox>public sealed class DragDropBehavior : Behavior<UIElement>
{
public static readonly DependencyProperty DropCommandProperty =
DependencyProperty.Register(
nameof(DropCommand),
typeof(ICommand),
typeof(DragDropBehavior));
public ICommand? DropCommand
{
get => (ICommand?)GetValue(DropCommandProperty);
set => SetValue(DropCommandProperty, value);
}
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.AllowDrop = true;
AssociatedObject.Drop += OnDrop;
AssociatedObject.DragOver += OnDragOver;
}
protected override void OnDetaching()
{
base.OnDetaching();
AssociatedObject.Drop -= OnDrop;
AssociatedObject.DragOver -= OnDragOver;
}
private void OnDragOver(object sender, DragEventArgs e)
{
e.Effects = e.Data.GetDataPresent(DataFormats.FileDrop)
? DragDropEffects.Copy
: DragDropEffects.None;
e.Handled = true;
}
private void OnDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
var files = (string[])e.Data.GetData(DataFormats.FileDrop)!;
DropCommand?.Execute(files);
}
}
}<Border Background="LightGray" MinHeight="100">
<b:Interaction.Behaviors>
<local:DragDropBehavior DropCommand="{Binding FileDroppedCommand}"/>
</b:Interaction.Behaviors>
<TextBlock Text="Drop files here" HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>public sealed class ShowMessageAction : TriggerAction<DependencyObject>
{
public static readonly DependencyProperty MessageProperty =
DependencyProperty.Register(
nameof(Message),
typeof(string),
typeof(ShowMessageAction));
public string Message
{
get => (string)GetValue(MessageProperty);
set => SetValue(MessageProperty, value);
}
protected override void Invoke(object parameter)
{
MessageBox.Show(Message, "Information",
MessageBoxButton.OK, MessageBoxImage.Information);
}
}<Button Content="Show Message">
<b:Interaction.Triggers>
<b:EventTrigger EventName="Click">
<local:ShowMessageAction Message="Hello, World!"/>
</b:EventTrigger>
</b:Interaction.Triggers>
</Button><Button Content="Close">
<b:Interaction.Triggers>
<b:EventTrigger EventName="Click">
<b:CallMethodAction TargetObject="{Binding RelativeSource={RelativeSource AncestorType=Window}}"
MethodName="Close"/>
</b:EventTrigger>
</b:Interaction.Triggers>
</Button>public sealed class MoveNextOnEnterBehavior : Behavior<UIElement>
{
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.KeyDown += OnKeyDown;
}
protected override void OnDetaching()
{
base.OnDetaching();
AssociatedObject.KeyDown -= OnKeyDown;
}
private void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
AssociatedObject.MoveFocus(
new TraversalRequest(FocusNavigationDirection.Next));
}
}
}| DO | DON'T |
|---|---|
✅ Implement OnDetaching in Behavior (prevent memory leaks) | ❌ Write event handlers directly in code-behind |
| ✅ Follow MVVM pattern (InvokeCommandAction) | ❌ Reference ViewModel directly in Behavior |
| ✅ Make configurable via DependencyProperty | ❌ Use hardcoded values |
| ✅ Design reusable Behaviors | ❌ Behaviors that only work with specific controls |
handling-wpf-input-commands - ICommand, RoutedCommandrouting-wpf-events - Routed Eventsimplementing-wpf-dragdrop - Drag and Drop~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.