[英]c# Storyboard Begin() Not Firing
我通過<Viewbox>
在畫布上有大約50個<Path>
元素。 <Viewbox>
也被嵌套。 當它們的位置與傳感器數據位置匹配時,我想更改<Path>
的不透明度。 該代碼一直運行到Begin()方法。 它不會給出錯誤,它不會執行任何操作。 我也嘗試創建其他NameScopes
但是無法指出正確的namspace。 比其他任何this
並不使它的開始()方法。 如果我在if語句內創建一個新的Scope:“ if (wantedNode is System.Windows.Shapes.Path)
”,它將使其一次進入Begin(),不會觸發,並且永遠不會回來!
if (angle > 0)
{
if (angle <= 180 && angle > 150)
{
if (mag <= sweetSpot)
{
//posAlertTxt.Text = "On target...";
}
else if (mag <= step)
{
selectedStep = "step0108";
}
else if (mag <= step * 2)
.
.
.
.
覆蓋所有角度和大小后:
redBrush.Color = Colors.IndianRed;
System.Windows.Media.Animation.DoubleAnimation opacityAnimation = new System.Windows.Media.Animation.DoubleAnimation();
opacityAnimation.To = 1.0;
opacityAnimation.Duration = TimeSpan.FromSeconds(1);
opacityAnimation.AutoReverse = true;
RegisterName("redBrush", redBrush);
Storyboard sb = new System.Windows.Media.Animation.Storyboard();
Storyboard.SetTargetName(opacityAnimation, "redBrush");
Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(SolidColorBrush.OpacityProperty));
sb.Children.Add(opacityAnimation);
object wantedNode = indicatorBounds.FindName(selectedStep);
if (wantedNode is System.Windows.Shapes.Path){
System.Windows.Shapes.Path wantedChild = wantedNode as System.Windows.Shapes.Path;
wantedChild.Fill = redBrush;
//System.Diagnostics.Debug.WriteLine(wantedChild.Opacity);
sb.Begin(this);
最后,XAML:
.
.
.
.
<Viewbox Name="forceGradientContainer" Width="126" Height="457"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Canvas.Left="117" Canvas.Top="17">
<Canvas Name="indicatorBounds" Width="126.378" Height="457.004">
<Canvas Name="holder">
.
.
.
.
<Path Fill="IndianRed" Opacity="0" x:Name="step0108" Data="F1 M 28.802,209.027 L 49.252,221.067 C 47.922,223.377 47.162,226.057 47.162,228.917 L 23.432,228.917 C 23.432,221.667 25.392,214.867 28.802,209.027 Z"/>`
.
.
.
</Canvas>
</Canvas>
</Viewbox>
嘗試
Storyboard.SetTarget(opacityAnimation, redBrush);
代替
RegisterName("redBrush", redBrush);
Storyboard.SetTargetName(opacityAnimation, "redBrush");
而且為什么不只為元素本身的不透明度設置動畫呢?
Storyboard.SetTarget(opacityAnimation, wantedChild);
Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.