アニメーションがTextBlock
です。 60秒では、FontSize
が8ptから200ptに増加します。テキストが大きくなるにつれてアニメーションが上下に動くことを除いて、すべてがうまくいきます。なぜこれが起こっており、これを避けることが可能ですか?WPF:アニメーションがスムーズでない
私は非常に単純なXAMLファイルを持っている:
<Window x:Class="Timer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="800"
Height="500"
Title="MainWindow"
Loaded="Window_Loaded">
<Grid>
<TextBlock
Name="TimerTextBlock"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="00h : 00m : 00.000s" />
</Grid>
</Window>
と同じように簡単なコードビハインド:
public partial class MainWindow : Window
{
private const string timerFormat = "{0:hh'h : 'mm'm : 'ss'.'fff's'}";
private DispatcherTimer dispatcherTimer;
private DateTime targetTime;
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
targetTime = DateTime.Now.AddSeconds(60);
double totalTime = targetTime.Subtract(DateTime.Now).TotalMilliseconds;
DoubleAnimation animation = new DoubleAnimation();
animation.From = TimerTextBlock.FontSize;
animation.To = 200;
animation.Duration = new Duration(targetTime.Subtract(DateTime.Now));
TimerTextBlock.BeginAnimation(TextBlock.FontSizeProperty, animation);
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Interval = TimeSpan.FromMilliseconds(1);
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
if (DateTime.Compare(targetTime, DateTime.Now) > 0)
{
TimerTextBlock.Text =
string.Format(timerFormat, targetTime.Subtract(DateTime.Now));
}
}
}
は、すべての明確化をありがとうございました。
「ピクセル分割」の問題は間違いないと私は結論づけました。コントロールが2つのピクセルの間のどこかに描かれなければならない状況になると、ちょっとチョップするのが理にかなっています。しかし、何とかこれを避ける方法はありますか? – Boris
私はインターネット上で答えを探していましたが、私はいくつかの "MatrixAnimations"に出くわしました。それは何ですか、それはトリックをすることができますか? (もしそうなら、どう?) – Boris