设置窗口大小(宽度和高度)的动画C#WPF
我正在寻找一些帮助动画窗口大小的一个打开的窗口! 我好像想不出这个 我只是在用自动取款机设置窗口大小(宽度和高度)的动画C#WPF,c#,wpf,xaml,animation,window,C#,Wpf,Xaml,Animation,Window,我正在寻找一些帮助动画窗口大小的一个打开的窗口! 我好像想不出这个 我只是在用自动取款机 this.Width = 500; 任何帮助都会很好! 谢谢。我自己已经回答了这个问题。下面是一些示例代码 static System.Windows.Forms.Timer _Timer = new System.Windows.Forms.Timer(); int _Stop = 0; private void This_Loaded(object sender, Rout
this.Width = 500;
任何帮助都会很好!
谢谢。我自己已经回答了这个问题。下面是一些示例代码
static System.Windows.Forms.Timer _Timer = new System.Windows.Forms.Timer();
int _Stop = 0;
private void This_Loaded(object sender, RoutedEventArgs e)
{
_Timer.Tick += new EventHandler(timer_Tick);
_Timer.Interval = (20);
resize(500,500)
}
private void timer_Tick(Object myObject, EventArgs myEventArgs)
{
if (_Stop == 0)
{
_RatioHeight = ((this.Height - _Height) / 12)* -1;
_RatioWidth = ((this.Width - _Width) / 12)* -1;
}
_Stop++;
this.Height += _RatioHeight;
this.Width += _RatioWidth;
if (_Stop == 12)
{
_Timer.Stop();
_Timer.Enabled = false;
_Timer.Dispose();
_Stop = 0;
this.Height = _Height;
this.Width = _Width;
}
}
public void resize(double _PassedHeight, double _PassedWidth)
{
_Height = _PassedHeight;
_Width = _PassedWidth;
_Timer.Enabled = true;
_Timer.Start();
}
以12“滴答”的速度快速调整窗口大小,可在_Timer.Interval内减慢。在12个刻度后,将通过最终调整大小使其达到精确大小来抛光
希望这能有所帮助。System.Windows.Threading.DispatcherTimer DispatcherTimer=新系统。Windows.Threading.DispatcherTimer();
System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += dispatcherTimer_Tick;
dispatcherTimer.Interval = new TimeSpan(0,0,0,0,10); // Control animation speed / how often the tick will be called.
dispatcherTimer.Start();
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
if ( this.Width < 500 )
{
this.Width += 10;
}
else
{
DispatcherTimer timer = (DispatcherTimer)sender;
timer.Stop();
}
}
Dispatchermer.Tick+=Dispatchermer\u Tick;
Dispatchermer.Interval=新的时间跨度(0,0,0,0,10);//控制动画速度/调用勾号的频率。
dispatchermer.Start();
私有void Dispatcher_Tick(对象发送方,事件参数e)
{
如果(此宽度<500)
{
这个。宽度+=10;
}
其他的
{
分派器计时器=(分派器)发送器;
timer.Stop();
}
}
您可以使用窗口动画,这里是xaml
<Window x:Class="dlgControls" Name="dlgControls"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="" Height="300" Width="300">
<Window.Resources>
<Storyboard x:Key="showWin">
<DoubleAnimation Storyboard.TargetName="dlgControls" Storyboard.TargetProperty="Height" Duration="0:0:.5" To="300" BeginTime="0:0:1"/>
</Storyboard>
<Storyboard x:Key="hideWin">
<DoubleAnimation Storyboard.TargetName="dlgControls" Storyboard.TargetProperty="Height" Duration="0:0:.5" To="150" BeginTime="0:0:1"/>
</Storyboard>
</Window.Resources>
<Grid RenderTransformOrigin="0.5,0.5">
<Button Name="btnOpen" Content="Open" HorizontalAlignment="Left" Margin="184,98,0,0" VerticalAlignment="Top" Width="75"/>
<Button Name="btnClose" Content="Close" HorizontalAlignment="Left" Margin="184,222,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
</Window>
真不敢相信这没有更多的选票。非常优雅,正好解决了我的问题
Imports System.Windows.Media.Animation
Public Class dlgControls
Dim showWin As Storyboard
Dim hideWin As Storyboard
Private Sub btnOpen_Click(sender As Object, e As Windows.RoutedEventArgs) Handles btnOpen.Click
BeginStoryboard(showWin)
End Sub
Private Sub dlgControls_Loaded(sender As Object, e As Windows.RoutedEventArgs) Handles Me.Loaded
showWin = Me.Resources("showWin")
hideWin = Me.Resources("hideWin")
End Sub
Private Sub btnClose_Click(sender As Object, e As Windows.RoutedEventArgs) Handles btnClose.Click
BeginStoryboard(hideWin)
End Sub
End Class