比较来自世界各地的卖家的域名和 IT 服务价格

窗口大小的动画改变 /宽度和高度/ C# WPF

我正在寻找有关开放窗口窗口技能大小的动画的帮助!
我似乎无法理解它!

我只是使用ATM。


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 "ticks" 非常快,可以放慢速度 _Timer.Interval. 后 12 将其大小的最终变化达成焦点,以确切的尺寸。

我希望它有所帮助,好像有人一样。

冰洋

赞同来自:

您可以使用窗口动画。 xaml


<window height="300" name="dlgControls" title="" width="300" x:class="dlgControls" xmlns="[url=http://schemas.microsoft.com/winfx/2006/xaml/presentation"]http://schemas.microsoft.com/w ... ot%3B[/url] xmlns:x="[url=http://schemas.microsoft.com/winfx/2006/xaml">]http://schemas.microsoft.com/w ... gt%3B[/url]
<window.resources>
<storyboard x:key="showWin">
<doubleanimation begintime="0:0:1" duration="0:0:.5" storyboard.targetname="dlgControls" storyboard.targetproperty="Height" to="300"></doubleanimation>
</storyboard>
<storyboard x:key="hideWin">
<doubleanimation begintime="0:0:1" duration="0:0:.5" storyboard.targetname="dlgControls" storyboard.targetproperty="Height" to="150"></doubleanimation>
</storyboard>
</window.resources>
<grid rendertransformorigin="0.5,0.5">
<button content="Open" horizontalalignment="Left" margin="184,98,0,0" name="btnOpen" verticalalignment="Top" width="75"></button>
<button content="Close" horizontalalignment="Left" margin="184,222,0,0" name="btnClose" verticalalignment="Top" width="75"></button>
</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

风见雨下

赞同来自:

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//;
}
}

要回复问题请先登录注册