Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Starting Storeboard based on property value

$
0
0

Hi, I did search for a solution to my problem but nothing to do.

I'm using Caliburn Micro into ma project, in the code below I have a image running by the storyboard and a coumple of buttons

and in the view model I have a property of type bool called ValveValue.

Now... when I click a button the property change to true or false depending which button I pressed.

What I would like to do is that when I click on Open button the property become true and the SbActionValve1 start and vice versa, when I click on Close button will start the SbActionValve2 which have different angle trasformation.

I lost a couple of days to resolve this problem so I will appreciate your help.

Thanks

  

<UserControl x:Class="WpfApp1.Views.ShellView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WpfApp1.Views"
             xmlns:cal="http://www.caliburnproject.org"
             mc:Ignorable="d" Width="582.716" Height="139.506">
    
    <UserControl.Resources>
        <Storyboard x:Key="SbActionValve1">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="imgProp">
                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="360"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="SbActionValve2">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="imgProp">
                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>   
    

    <Grid Background="#FFD4D4D4">

        <Image x:Name="imgProp" Source="/WpfApp1;component/Images/propeller.png" Margin="25,34,457,33" RenderTransformOrigin="0.5,0.5">
            <Image.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Image.RenderTransform>

        </Image>

        <!--Button Open Valve-->
        <Button cal:Message.Attach="SetValve('true')"  Content="Open" HorizontalAlignment="Left" Margin="339,54,0,0" VerticalAlignment="Top" Width="75"/>

        <!--Button Close Valve-->
        <Button cal:Message.Attach="SetValve('false')" Content="Close" HorizontalAlignment="Left" Margin="427,54,0,0" VerticalAlignment="Top" Width="75"/>


        <TextBox x:Name="textBox" Text="{Binding Path=ValveValue}"  Margin="177,54,280,58">
            <TextBox.Style>
                <Style TargetType="{x:Type TextBox}">
                    <Setter Property="Foreground" Value="#FFE8E8E8"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ValveValue}" Value="True">
                            <Setter Property="Foreground" Value="Green"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding ValveValue}" Value="False">
                            <Setter Property="Foreground" Value="Red"/>
                            <DataTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource SbActionValve1}"/>
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource SbActionValve2}"/>
                            </DataTrigger.ExitActions>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBox.Style>
        </TextBox>

    </Grid>

</UserControl>



Gioking http://social.msdn.microsoft.com/Forums/en-US/user


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>