Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
maxkatz6 opened this issue Oct 28, 2021 · 1 comment

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 🐭

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

No branches or pull requests

3 participants