Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

DataTriggerBehavior won't fire actions on initial state right after attaching to the owner #80

@maxkatz6

Description

@maxkatz6

DataTriggerBehavior currently executes actions when specific condition is executed as true, as expected.
But DataTriggerBehavior does not execute anything when it was attached and initial condition is true as well.

Consider example below. Trigger should execute actions when binding results in value 50. But if 50 is a default value, trigger won't see that, until you change value to 55 and then back to 50.

<UserControl x:Class="BehaviorsTestApplication.Views.Pages.DataTriggerBehaviorView"
             xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:i="using:Avalonia.Xaml.Interactivity"
             xmlns:ia="using:Avalonia.Xaml.Interactions.Core"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:vm="using:BehaviorsTestApplication.ViewModels"
             x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
             mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
  <Design.DataContext>
    <vm:MainWindowViewModel />
  </Design.DataContext>
  <Grid RowDefinitions="*,Auto">
    <Rectangle Name="DataTriggerRectangle" 
               Grid.Row="0" Margin="5"
               Fill="{DynamicResource BlueBrush}"
               Stroke="{DynamicResource GrayBrush}"
               StrokeThickness="5">
      <i:Interaction.Behaviors>
        <ia:DataTriggerBehavior Binding="{Binding #Slider.Value}" 
                                ComparisonCondition="Equal" 
                                Value="50">
          <ia:ChangePropertyAction TargetObject="{Binding #DataTriggerRectangle}" 
                                   PropertyName="Fill"
                                   Value="{DynamicResource YellowBrush}" />
        </ia:DataTriggerBehavior>
      </i:Interaction.Behaviors>
    </Rectangle>
    <StackPanel Grid.Row="1" 
                Margin="5,0,5,5" 
                Orientation="Horizontal"
                HorizontalAlignment="Center"
                VerticalAlignment="Center">
      <TextBlock Text="{Binding #Slider.Value}" 
                 VerticalAlignment="Center" 
                 Width="50"
                 Foreground="{DynamicResource GrayBrush}" />
      <Slider Name="Slider" Value="50" Width="400" IsSnapToTickEnabled="True" TickFrequency="1" />
    </StackPanel>
  </Grid>
</UserControl>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions