So I am trying to make an animation for a memory game project. The animation I am having trouble with is the flip animation. I have no problem making the image flip, but I want to make it change the image after the scale.x went from -1 to 0. This is what I have so far:
<Window.Resources>
<ControlTemplate TargetType="Button" x:Key="ImageButton">
<Image Source="gurbe1.jpg"
x:Name="image"
Height="{TemplateBinding Height}"
Width="{TemplateBinding Width}" />
</ControlTemplate>
</Window.Resources>
<Grid>
<Button Template="{StaticResource ImageButton}"
Width="100" Click="Button_Click" RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<ScaleTransform x:Name="AnimatedScaleTransform" ScaleX="-1" />
</Button.RenderTransform>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation To="0" Duration="0:0:1" Storyboard.TargetName="AnimatedScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleX)"/>
<DoubleAnimation To="1" BeginTime="0:0:1" Duration="0:0:1" Storyboard.TargetName="AnimatedScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleX)"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
</Window>
I already looked on here and tried some stuff, but I couldn't get it to work :
xaml change image source
How can I do multiple animations in a single storyboard in C#/XAML?
For people also having this problem, it's as simple as this:
<Grid>
<Button Width="100" Click="Button_Click" RenderTransformOrigin="0.5,0.5" Height="100">
<Button.RenderTransform>
<ScaleTransform x:Name="AnimatedScaleTransform" ScaleX="-1" />
</Button.RenderTransform>
<Button.Template>
<ControlTemplate>
<Image Source="gurbe1.jpg"/>
</ControlTemplate>
</Button.Template>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation To="0" Duration="0:0:1" Storyboard.TargetName="AnimatedScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleX)"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
<Button Width="100" Click="Button_Click" RenderTransformOrigin="0.5,0.5" Height="100">
<Button.RenderTransform>
<ScaleTransform x:Name="AnimatedScaleTransform2" ScaleX="0" />
</Button.RenderTransform>
<Button.Template>
<ControlTemplate>
<Image Source="gurbe2.jpg"/>
</ControlTemplate>
</Button.Template>
<Button.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation From="0" To="1" BeginTime="0:0:2.3" Duration="0:0:1" Storyboard.TargetName="AnimatedScaleTransform2" Storyboard.TargetProperty="(ScaleTransform.ScaleX)"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
It's not smooth atm, but you can get pretty close by adjusting the begin time
Related
I'm trying to make a flip animation, and have one that flips when it's a loaded RoutedEvent, but I want it to flip when the RoutedEvent is Button.Click. This is my code so far:
<Grid>
<Button Width="100" Click="Button_Click" RenderTransformOrigin="0.5,0.5" Height="100">
<Button.RenderTransform>
<ScaleTransform x:Name="AnimatedScaleTransform" ScaleX="-1" />
</Button.RenderTransform>
<Button.Template>
<ControlTemplate>
<Image Source="gurbe1.jpg"/>
</ControlTemplate>
</Button.Template>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard x:Name="Storyboard1" Completed="Storyboard1_Completed">
<DoubleAnimation To="0" Duration="0:0:1" Storyboard.TargetName="AnimatedScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleX)"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
<Button Width="100" Click="Button_Click" RenderTransformOrigin="0.5,0.5" Height="100">
<Button.RenderTransform>
<ScaleTransform x:Name="AnimatedScaleTransform2" ScaleX="0" />
</Button.RenderTransform>
<Button.Template>
<ControlTemplate>
<Image Source="gurbe2.jpg"/>
</ControlTemplate>
</Button.Template>
<Button.Triggers>
<EventTrigger RoutedEvent="loaded">
<BeginStoryboard>
<Storyboard x:Name="Storyboard2">
<DoubleAnimation From="0" To="1" BeginTime="0:0:2.3" Duration="0:0:1" Storyboard.TargetName="AnimatedScaleTransform2" Storyboard.TargetProperty="(ScaleTransform.ScaleX)"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
So is there a way to start the storyboards with just one click?
So i think i got it:
XAML
<Window.Resources>
<BeginStoryboard x:Key="begin">
<Storyboard x:Name="Storyboard1">
<DoubleAnimation To="0" Duration="0:0:1" Storyboard.TargetName="AnimatedScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleX)"/>
</Storyboard>
</BeginStoryboard>
<BeginStoryboard x:Key="twa">
<Storyboard x:Name="Storyboard2">
<DoubleAnimation From="0" To="1" BeginTime="0:0:2.3" Duration="0:0:1" Storyboard.TargetName="AnimatedScaleTransform2" Storyboard.TargetProperty="(ScaleTransform.ScaleX)"/>
</Storyboard>
</BeginStoryboard>
</Window.Resources>
<Grid>
<Button x:Name="button1" Width="100" Click="button1_Click" RenderTransformOrigin="0.5,0.5" Height="100">
<Button.RenderTransform>
<ScaleTransform x:Name="AnimatedScaleTransform" ScaleX="-1" />
</Button.RenderTransform>
<Button.Template>
<ControlTemplate>
<Image Source="gurbe1.jpg"/>
</ControlTemplate>
</Button.Template>
</Button>
<Button Width="100" Click="button1_Click" RenderTransformOrigin="0.5,0.5" Height="100">
<Button.RenderTransform>
<ScaleTransform x:Name="AnimatedScaleTransform2" ScaleX="0" />
</Button.RenderTransform>
<Button.Template>
<ControlTemplate>
<Image Source="gurbe2.jpg"/>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
C#
private void Clicked_Button(object sender, RoutedEventArgs e)
{
BeginStoryboard sb = this.FindResource("begin2") as BeginStoryboard;
sb.Storyboard.Begin();
}
In the ControlTemplate of the ToggleButton, I'm defining a Border which has a Polygon. The problem is that the EventTrigger is only applicable on the polygon, not the entire Border.
<ToggleButton Padding="30, 10">
<ToggleButton.Template>
<ControlTemplate TargetType="ToggleButton">
<Border Background="Red">
<Polygon Points="12,12 12,26, 22,19" Fill="#4B86B1" Margin="0,0,5,0" RenderTransformOrigin="0.6,0.5">
<Polygon.RenderTransform>
<RotateTransform x:Name="rotRect" Angle="0"/>
</Polygon.RenderTransform>
<Polygon.Effect>
<DropShadowEffect ShadowDepth="0.5" Direction="0" Color="Black" Opacity="1" BlurRadius="1"/>
</Polygon.Effect>
</Polygon>
</Border>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="ToggleButton.Checked">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="rotRect" Storyboard.TargetProperty="Angle" From="0" To="90" Duration="0:0:0.5"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="ToggleButton.Unchecked">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="rotRect" Storyboard.TargetProperty="Angle" From="90" To="0" Duration="0:0:0.5"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
In case you wanted to just rotate the polygon around its center, get rid of the RenderTransformOrigin and instead set a CenterX and CenterY on your Transformation:
<ToggleButton Margin="150,100">
<ToggleButton.Template>
<ControlTemplate TargetType="ToggleButton">
<Border Background="Red">
<Polygon Points="12,12 12,26, 22,19" Fill="#4B86B1" Margin="0,0,5,0">
<Polygon.RenderTransform>
<RotateTransform x:Name="rotRect" Angle="0" CenterX="17" CenterY="19"/>
</Polygon.RenderTransform>
<Polygon.Effect>
<DropShadowEffect ShadowDepth="0.5" Direction="0" Color="Black" Opacity="1" BlurRadius="1"/>
</Polygon.Effect>
</Polygon>
</Border>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="ToggleButton.Checked">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="rotRect" Storyboard.TargetProperty="Angle" From="0" To="90" Duration="0:0:0.5"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="ToggleButton.Unchecked">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="rotRect" Storyboard.TargetProperty="Angle" From="90" To="0" Duration="0:0:0.5"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
If you really want to rotate the button too, simply move the Transformation to the border:
<ToggleButton Margin="100">
<ToggleButton.Template>
<ControlTemplate TargetType="ToggleButton">
<Border Background="Red">
<Border.RenderTransform>
<RotateTransform x:Name="rotRect" Angle="0"/>
</Border.RenderTransform>
<Polygon Points="12,12 12,26, 22,19" Fill="#4B86B1" Margin="0,0,5,0">
<Polygon.Effect>
<DropShadowEffect ShadowDepth="0.5" Direction="0" Color="Black" Opacity="1" BlurRadius="1"/>
</Polygon.Effect>
</Polygon>
</Border>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="ToggleButton.Checked">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="rotRect" Storyboard.TargetProperty="Angle" From="0" To="90" Duration="0:0:0.5"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="ToggleButton.Unchecked">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="rotRect" Storyboard.TargetProperty="Angle" From="90" To="0" Duration="0:0:0.5"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
The problem is that your Polygon is actually quite larger than it appears; the horizontal and vertical alignment both default to Stretch, so even though the shape you define is relatively small, the Polygon is being laid out such that it fills your entire Border (less a 5pt margin on the right).
I would make two changes:
Set the horizontal and vertical alignments to Left and Top, respectively.
Get rid of the 12pt of 'empty' space inside the polygon, and shift them to the polygon's Margin.
<Polygon Points="0,0 0,14 10,7" Fill="#4B86B1" RenderTransformOrigin="0.5,0.6"
Margin="12,12,5,0" HorizontalAlignment="Left" VerticalAlignment="Top">
<Polygon.RenderTransform>
<RotateTransform x:Name="rotRect" Angle="0" />
</Polygon.RenderTransform>
<Polygon.Effect>
<DropShadowEffect ShadowDepth="0.5" Direction="0" Color="Black"
Opacity="1" BlurRadius="1"/>
</Polygon.Effect>
</Polygon>
I also generally use Path over Polygon (and most other Shape classes, except perhaps Ellipse). I find it helps keep me reasonably fluent in the Path Markup Syntax, which is useful when I need to create more elaborate geometry. An equivalent Path to your Polygon would be:
<Path Data="M 0,0 L 0,14 10,7 Z" ... />
It's up to you which to use. One is not inherently 'better' than the other.
How to make the animation start of the TextBlock when entering (hovering) the button
In TextBlock I want that the <EventTrigger RoutedEvent will be in Input2 at MouseEnter, How can I do that
<EventTrigger RoutedEvent=Input2.MouseEnter doesn't recognized
The button:
<Button Grid.Row="0" Name="Input2" Click="Input_Click" MouseEnter="Input_MouseEnter" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}">
<Button.Template>
<ControlTemplate>
<Border HorizontalAlignment="Center" VerticalAlignment="Center" >
<Image Source= "C:\Users\Me\input.png"
Width="40"
Height="40"/>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
The TextBlock:
<TextBlock Grid.Row="0" Name="Input_Name1" Text="Input" FontSize="40" FontFamily="/10KHours;component/Font_count/#Dancing Script" VerticalAlignment="Center" Height="48" Margin="65.346,33.6,-102.081,36">
<TextBlock.Triggers>
<EventTrigger RoutedEvent="TextBlock.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="Input_Name1"
Storyboard.TargetProperty="Opacity"
From="1.0" To="0.0" Duration="0:0:5"
AutoReverse="true" RepeatBehavior="1x">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
The basic idea to change the style of the TextBlock is totally correct. Add a DataTrigger and bind it to the the IsMouseOver of the Button you are going to hover. Using the IsMouseOver is propaply the simplest way to get the desired information. Here is a minimal example:
<Button x:Name="btn" Content="Hover me"/>
<TextBlock x:Name="tb" Text="Input">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=btn, Path=IsMouseOver}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="Opacity"
From="1.0" To="0.0" Duration="0:0:1"
AutoReverse="true" RepeatBehavior="1x">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
Please check the below example first
animation example
i want to do this in my wpf windows application. plz help me
i am using 3 buttons in grid.row="0"
and three stack panels in grid.row="1"
when user clicks on any button the appropriate stack panel should move in and and other should move out.
I am new to WPF and i tried below.
<Grid>
<Grid.Triggers>
<EventTrigger SourceName="btnPNB" RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard x:Name="StoryBoard1">
<Storyboard>
<DoubleAnimation x:Name="dbMoveOut" Storyboard.TargetName="sPanelPNB"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
From="0" To="600" AutoReverse="False">
</DoubleAnimation>
<DoubleAnimation x:Name="dbMoveIn" Storyboard.TargetName="sPanelOtherBank"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
From="-550" To="0" AutoReverse="False">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger SourceName="btnOther" RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard x:Name="StoryBoard2">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="sPanelOtherBank"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
From="-550" To="0" AutoReverse="False">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger SourceName="btnCAIIB" RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard x:Name="StoryBoard3">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="sPanelCAIIB"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
From="-550" To="0" AutoReverse="False">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Grid.Triggers>
<Button x:Name="btnPNB" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="20,0,0,0" Content="PNB" Click="moveSP_Click"></Button>
<Button x:Name="btnOther" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="70,0,0,0" Content="OTher" Click="moveSP_Click"></Button>
<Button x:Name="btnCAIIB" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="150,0,0,0" Content="CAIIB" Click="moveSP_Click"></Button>
<StackPanel x:Name="sPanelPNB" VerticalAlignment="Bottom" Orientation="Horizontal">
<StackPanel.RenderTransform>
<TranslateTransform X="-550" Y="0"></TranslateTransform>
</StackPanel.RenderTransform>
<Image Source="1_1.jpg" Margin="10,0,0,0" Width="100" HorizontalAlignment="Left" VerticalAlignment="Bottom">
</Image>
<Image Source="1_2.png" Width="100" Margin="50,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Bottom">
</Image>
<Image Source="1_3.png" Width="100" Margin="50,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Bottom">
</Image>
</StackPanel>
<StackPanel x:Name="sPanelOtherBank" VerticalAlignment="Bottom" Orientation="Horizontal">
<StackPanel.RenderTransform>
<TranslateTransform X="-550" Y="0"></TranslateTransform>
</StackPanel.RenderTransform>
<Image Source="2_1.png" Margin="10,0,0,0" Width="100" HorizontalAlignment="Left" VerticalAlignment="Bottom">
</Image>
<Image Source="2_2.jpg" Width="100" Margin="50,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Bottom">
</Image>
<Image Source="2_3.png" Width="100" Margin="50,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Bottom">
</Image>
</StackPanel>
<StackPanel x:Name="sPanelCAIIB" VerticalAlignment="Bottom" Orientation="Horizontal">
<StackPanel.RenderTransform>
<TranslateTransform X="-550" Y="0"></TranslateTransform>
</StackPanel.RenderTransform>
<Image Source="3_1.png" Margin="10,0,0,0" Width="100" HorizontalAlignment="Left" VerticalAlignment="Bottom">
</Image>
<Image Source="3_2.png" Width="100" Margin="50,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Bottom">
</Image>
<Image Source="3_3.jpg" Width="100" Margin="50,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Bottom">
</Image>
</StackPanel>
</Grid>
Here is what you want. You have update your panels everytime. And I personally, would add duration. But in this example you will notice your panels if you resize your window
<Grid>
<Grid.Triggers>
<EventTrigger SourceName="btnRed" RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard x:Name="StoryBoard1">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="sPanelRed"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
To="0"/>
<DoubleAnimation Storyboard.TargetName="sPanelBlue"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
To="-550"/>
<DoubleAnimation Storyboard.TargetName="sPanelBlack"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
To="-550"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger SourceName="btnBlue" RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard x:Name="StoryBoard2">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="sPanelRed"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
To="600" AutoReverse="False"/>
<DoubleAnimation Storyboard.TargetName="sPanelBlue"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
To="0"/>
<DoubleAnimation Storyboard.TargetName="sPanelBlack"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
To="-550"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger SourceName="btnBlack" RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard x:Name="StoryBoard3">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="sPanelRed"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
To="600"/>
<DoubleAnimation Storyboard.TargetName="sPanelBlue"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
To="600"/>
<DoubleAnimation Storyboard.TargetName="sPanelBlack"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
To="0"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Grid.Triggers>
<Button x:Name="btnRed" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="20,0,0,0" Content="show red"></Button>
<Button x:Name="btnBlue" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,0,359,0" Content="show blue"></Button>
<Button x:Name="btnBlack" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,0,279,0" Content="show black"></Button>
<StackPanel x:Name="sPanelRed" VerticalAlignment="Bottom" Orientation="Horizontal" Height="10" Background="Red">
<StackPanel.RenderTransform>
<TranslateTransform X="-550" Y="0"></TranslateTransform>
</StackPanel.RenderTransform>
</StackPanel>
<StackPanel x:Name="sPanelBlue" VerticalAlignment="Bottom" Orientation="Horizontal" Height="10" Background="Blue">
<StackPanel.RenderTransform>
<TranslateTransform X="-550" Y="0"></TranslateTransform>
</StackPanel.RenderTransform>
</StackPanel>
<StackPanel x:Name="sPanelBlack" VerticalAlignment="Bottom" Orientation="Horizontal" Height="10" Background="Black">
<StackPanel.RenderTransform>
<TranslateTransform X="-550" Y="0"></TranslateTransform>
</StackPanel.RenderTransform>
</StackPanel>
</Grid>
I did simplify your animation to something like this so you can work on it :
<Grid>
<Grid.Triggers>
<EventTrigger SourceName="btnPNB" RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard x:Name="StoryBoard1">
<Storyboard>
<DoubleAnimation x:Name="dbMoveOut" Storyboard.TargetName="sPanelPNB"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
From="0" To="600" AutoReverse="False">
</DoubleAnimation>
<DoubleAnimation x:Name="dbMoveIn" Storyboard.TargetName="sPanelOtherBank"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
From="-550" To="0" AutoReverse="False">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger SourceName="btnOther" RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard x:Name="StoryBoard2">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="sPanelOtherBank"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
From="-550" To="0" AutoReverse="False">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger SourceName="btnCAIIB" RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard x:Name="StoryBoard3">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="sPanelCAIIB"
Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
From="-550" To="0" AutoReverse="False">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Grid.Triggers>
<Button x:Name="btnPNB" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="20,0,0,0" Content="PNB" ></Button>
<Button x:Name="btnOther" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="70,0,0,0" Content="OTher" ></Button>
<Button x:Name="btnCAIIB" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="150,0,0,0" Content="CAIIB" ></Button>
<Grid x:Name="sPanelPNB" Height="100" VerticalAlignment="Bottom" >
<Border Background="Aquamarine"></Border>
</Grid>
<Grid x:Name="sPanelOtherBank" Height="100" VerticalAlignment="Bottom" >
<Grid.RenderTransform>
<TranslateTransform X="-550" Y="0"></TranslateTransform>
</Grid.RenderTransform>
<Border Background="Blue"></Border>
</Grid>
<Grid x:Name="sPanelCAIIB" Height="100" VerticalAlignment="Bottom" >
<Grid.RenderTransform>
<TranslateTransform X="-550" Y="0"></TranslateTransform>
</Grid.RenderTransform>
<Border Background="Violet"></Border>
</Grid>
</Grid>
I think the title of my question is some mess! Sorry!
I have two Grid in same window. First named loginBox and second is operationBox. I want to disappear loginBox after validating user, using DoubleAnimation class and then operationBox will be appear in same time (during 00:00:01).
Scenario:
Grid named loginBox is showing when window shown. After user clicked on btnLogin, loginBox start disappearing using DoubleAnimation on it's Opacity property and in same time, operationBox will be appear using same technique.
After ending operation, user clicks on btnLogout and operationBox start disappearing and loginBox appearing by DoubleAnimation.
The problem is because operationBox grid is overloginBox grid, User can't do anything in loginbox! How ever operationBox.Opacity=0 ;but nothing can do with loginBox grid at start up!
CODE:
<!--Login Box-->
<Grid Background="Transparent" Name="loginBox" VerticalAlignment="Center" HorizontalAlignment="Center">
<Button Content="ورود" Height="23" HorizontalAlignment="Left" Margin="344,199,0,0" Name="btnLogin" VerticalAlignment="Top" Width="75" IsDefault="True"
Click="btnLogin_Click" >
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="loginBox"
Storyboard.TargetProperty="(Grid.Opacity)"
From="1" To="0" Duration="0:0:1" AutoReverse="False" />
<DoubleAnimation
Storyboard.TargetName="operationBox"
Storyboard.TargetProperty="(Grid.Opacity)"
From="0" To="1" Duration="0:0:1" AutoReverse="False" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
.
.
.
</Grid>
.
.
.
<!--Operation Box-->
<Grid Background="Transparent" Name="operationBox" Opacity="0" Visibility="Hidden">
...
<Button Content="خروج" Height="23"
HorizontalAlignment="Left" Margin="15,324,0,0" Name="btnLogout"
VerticalAlignment="Top" Width="75" Click="btnLogout_Click">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="operationBox"
Storyboard.TargetProperty="(Grid.Opacity)"
From="1" To="0" Duration="0:0:1" AutoReverse="False" />
<DoubleAnimation
Storyboard.TargetName="loginBox"
Storyboard.TargetProperty="(Grid.Opacity)"
From="0" To="1" Duration="0:0:1" AutoReverse="False" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
and finally, Sorry for bad grammar! :)
Try adding operationBox.IsHitTestVisible="False"
Update
Try to add something like this
<Grid Grid.ZIndex="4" Background="Green" Opacity="0.4" Name="loginBox" VerticalAlignment="Center" HorizontalAlignment="Center">
<Grid.Style>
<Style>
<Style.Triggers>
<Trigger Property="Grid.Opacity" Value="0.0">
<Setter Property="Grid.IsHitTestVisible" Value="False"/>
</Trigger>
</Style.Triggers>
</Style>
</Grid.Style>
<!-- ... -->