Skip to content
This repository has been 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

Open
maxkatz6 opened this issue Oct 28, 2021 · 2 comments

Comments

@maxkatz6
Copy link
Member

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>
@SuperJMN
Copy link

Same problem detected 🐭

@izaksuilov
Copy link

I have suggested the solution in this PR

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants