The easiest way is to add a slider to your page. The slider can be minimized and is used only for the convenience of animation. Animate the Value property of the slider. In the ValueChanged event of the slider, the width of the window is updated. For this you need increased traction.
It looks something like this:
Xaml
<UserControl.Resources> <Storyboard x:Name="Storyboard1"> <DoubleAnimation Duration="0:0:1" To="750" Storyboard.TargetProperty="(RangeBase.Value)" Storyboard.TargetName="slider1"> <DoubleAnimation.EasingFunction> <BounceEase EasingMode="EaseOut"/> </DoubleAnimation.EasingFunction> </DoubleAnimation> </Storyboard> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="Green"> <Button Width="50" Height="32" Click="Button_Click">Test</Button> <Slider Visibility="Collapsed" VerticalAlignment="Bottom" x:Name="slider1" Maximum="1000" ValueChanged="slider1_ValueChanged" /> </Grid>
Code for
private void Button_Click(object sender, RoutedEventArgs e) { Storyboard1.Begin(); } private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) { Application.Current.MainWindow.Width = e.NewValue; }
source share