none
Trigger não dispara com Attached Property RRS feed

  • Pergunta

  • Por que o Trigger da animação em Syle não está sendo disparado?

    using System.Windows;
    
    namespace Brincando_com_C
    {
        public class Class1
        {
    
            public static readonly DependencyProperty ValueProperty = DependencyProperty.RegisterAttached("Value", typeof(bool), typeof(Class1), new PropertyMetadata(false));
         
            public static void SetValue(DependencyObject d, bool value)
            {
                d.SetValue(ValueProperty, value);
            }
    
            public static bool GetValue(DependencyObject d)
            {
                return (bool)d.GetValue(ValueProperty);
            }
        }
    }

    Style:

     <!-- Botão -->
        <Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
            <Setter Property="Background" Value="White"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
                            <Grid>
                                <!-- Content Presenter-->
                                <ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
    
                                <!-- Spinner -->
                                <Image Name="ISpin" Source="https://img.icons8.com/metro/26/000000/spinner-frame-4.png" Width="40"   Height="40" VerticalAlignment="Center" >
    
                                    <Image.Style >
                                        <Style TargetType="Image" >
    
                                            <Setter Property="RenderTransformOrigin" Value="0.5, 0.5" />
                                            <Setter Property="RenderTransform">
                                                <Setter.Value>
                                                    <RotateTransform></RotateTransform>
                                                </Setter.Value>
                                            </Setter>
    
                                            <Style.Resources>
                                                <Storyboard x:Key="Spin">
                                                    <DoubleAnimation
                                                                Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"
                                                                From="0"
                                                                To="360"
                                                                Duration="0:0:2"
                                                                RepeatBehavior="Forever" />
                                                </Storyboard>
                                            </Style.Resources>
    
                                            <Style.Triggers>
                                                <Trigger Property="local:Class1.Value"  Value="True" >
                                                    <Trigger.EnterActions>
                                                        <BeginStoryboard Name="SpinStoryboard" Storyboard="{StaticResource Spin}" />
                                                    </Trigger.EnterActions>
                                                    <Trigger.ExitActions>
                                                        <RemoveStoryboard BeginStoryboardName="SpinStoryboard" />
                                                    </Trigger.ExitActions>
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Image.Style>
                                </Image>
                            </Grid>
                        </Border>
    
    
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsDefaulted" Value="true">
                                <Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Background" TargetName="border" Value="LightBlue" />
                            </Trigger>
                            
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    Controle:

     <Button local:Class1.Value="{Binding isEnable}" Content="Load" FontSize="24" Margin="5 10" Background="White" BorderBrush="White" Style="{DynamicResource ButtonStyle1}"/>




    • Editado _Lucas_-Pedro segunda-feira, 4 de novembro de 2019 12:44
    domingo, 3 de novembro de 2019 15:22