Hi,
You can animate the Width property of Window when you want the size changes. In the following example, when we scroll the mouse whell, the Window's Width property will be animated acroding to the current value of mouse wheel.
XAML code:
<Window x:Class="_temple.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
x:Name="window1" MouseWheel="Window_MouseWheel">
<Grid x:Name="g1">
</Grid>
</Window> In the code behind:
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Animation;
namespace _temple
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Window_MouseWheel(object sender, MouseWheelEventArgs e)
{
int delta = e.Delta;
double w1 = this.window1.ActualWidth;
double w2 = w1 + 2 * delta / 10;
DoubleAnimation anima = new DoubleAnimation();
anima.Duration = new Duration(TimeSpan.FromSeconds(0.3));
anima.From = w1;
anima.To = w2;
anima.FillBehavior = FillBehavior.HoldEnd;
window1.BeginAnimation(Window.WidthProperty, anima);
}
}
}
Thanks.
Jim Zhou -MSFT