我有一個需要提供狀態更新的應用程式,但它們很容易錯過。我想在發布訊息時非常輕松且非常簡短地脈沖狀態欄。到目前為止,我看到的幾乎所有指南都只列出了如何在懸停或單擊時使用 XAML 而不是實際的 C# 進行設定。當我在 C# 中更新狀態訊息時,我想呼叫一個函式來脈沖條:
這就是我所擁有的,它根本不起作用。
private void PulseStatus()
{
ColorAnimation animation;
animation = new ColorAnimation();
animation.To = Color.FromRgb(111, 80, 80);
animation.Duration = new Duration(TimeSpan.FromSeconds(.4));
animation.AutoReverse =true;
StatusArea.Background.BeginAnimation(WrapPanel.BackgroundProperty,animation);
}
uj5u.com熱心網友回復:
我試過了,我發現了一些錯誤。它與 XAML 無關,因為可以用 XAML 撰寫的所有內容也可以用 C# 撰寫。
然而:
首先,您要為 SolidBrush 物件的 Color 屬性設定影片。其次,至少在我的嘗試中,我無法為包裝面板的預設背景畫筆設定影片(它說它是“密封的”)。您可能還希望將 RepeatBehavior 設定為 Forever,以保持影片運行。
ColorAnimation animation;
animation = new ColorAnimation();
animation.To = Color.FromRgb(111, 80, 80);
animation.Duration = new Duration(TimeSpan.FromSeconds(.4));
animation.AutoReverse = true;
animation.RepeatBehavior = RepeatBehavior.Forever;
var clonedBackgroundBrush = wrap.Background.Clone();
wrap.Background = clonedBackgroundBrush;
clonedBackgroundBrush.BeginAnimation(SolidColorBrush.ColorProperty, animation);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/439562.html
上一篇:WPF視窗標題欄
