RenderTransform.TranslateTransform animating in usercontrol in wpf

user-controls, wpf

Solution

Just `Clip` the `button_panel` when it leaves the `Border` with `ClipToBounds="True"` on the `Border`

something like:

...
<Border BorderBrush="SeaGreen"
        BorderThickness="2"
        ClipToBounds="True"
        CornerRadius="4">
...

Now with `ClipToBounds="True"` being set on the `Border`, any child of the `Border` which is outside the `Border` is not going to be visible.

This would thus satisfy your requirement of having the `StackPanel` invisible when the mouse is not over the image as well since `TranslateTransform` keeps it outside the `Border`. Thus you only see the `StackPanel` when mouse is over the image and the Slide in/out is only visible inside the `Border`.

Problem

i want to create a wpf usercontrol that displays an Image and has a toolbar panel, i want to set features listed below to the my userControl: - tool bar panel hidden when mouse cursor is out side of the usercontrol. - When mouse cursor enter the usercontrol,toolbar panel move up from the bottom of the usercontrol and locate at the bottom of the usercontrol. i create it but ,i have a problem , see bellow: when mouse cursor enter the UserControl: and when mouse cursor leaved UserControl: My Problem: when panel is moving out side of the UserControl,the out side parts must be invisible, like bellow: my UserControl's Xaml codes: ``` <UserControl.Resources> <Storyboard x:Key="SB_MouseEnter"> <DoubleAnimation To="0" Storyboard.TargetName="button_panel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" Duration="0:0:0.2"/> </Storyboard> <Storyboard x:Key="SB_MouseLeave"> <DoubleAnimation To="40" Storyboard.TargetName="button_panel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" Duration="0:0:0.2"/> </Storyboard> </UserControl.Resources> <UserControl.Triggers> <EventTrigger RoutedEvent="Mouse.MouseEnter"> <BeginStoryboard Storyboard="{StaticResource ResourceKey=SB_MouseEnter}"/> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseLeave"> <BeginStoryboard Storyboard="{StaticResource ResourceKey=SB_MouseLeave}"/> </EventTrigger> </UserControl.Triggers> <Border CornerRadius="4" BorderBrush="SeaGreen" BorderThickness="2"> <Grid> <Image Source="Images/Koala.jpg"/> <StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" Name="button_panel" Height="40" RenderTransformOrigin="0.5,0.5"> <StackPanel.RenderTransform> <TranslateTransform Y="40"/> </StackPanel.RenderTransform> <StackPanel.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="Black" Offset="1"/> <GradientStop Color="#66FFFFFF"/> </LinearGradientBrush> </StackPanel.Background> <Button Padding="5" Margin="5,0" Width="80" Height="30"> Open </Button> <Button Padding="5" Margin="5,0" Width="80" Height="30"> Clear </Button> </StackPanel> </Grid> </Border> ```

Original source