繁体   English   中英

C#情节提要Begin()未触发

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM