English 中文(简体)
在法典中采用故事板进行估算的问题
原标题:Issue applying an animation using a storyboard in code

我有<条码>Canvas,有<条码>,<>Ellipse,标有<条码>。

<!-- Boilerplate -->
<Window x:Class="WpfApplication6.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:WpfApplication6="clr-namespace:WpfApplication6"
        Title="MainWindow" Height="350" Width="525"
        SnapsToDevicePixels="True">
  <Grid>
    <Canvas x:Name="DrawingCanvas">
      <!-- ##### Item of interest, below ##### -->
      <Ellipse x:Name="Marker" Canvas.Left="200" Canvas.Top="100" 
               Width="25" Height="25" Stroke="Black" Fill="#E0E000">
        <Ellipse.Effect>
          <BlurEffect x:Name="MarkerBlurEffect" Radius="0.0" />
        </Ellipse.Effect>
      </Ellipse>
    </Canvas>
  </Grid>
</Window>

我试图以方案方式给出的斜体:

  DoubleAnimation blurEffectAnimation=new DoubleAnimation
  {
    From=0, 
    To=10, 
    Duration=TimeSpan.FromSeconds(2.0)
  };

  // If I uncomment the line below, the blur effect animation works perfectly
  //Marker.Effect.BeginAnimation(BlurEffect.RadiusProperty, blurEffectAnimation); 

  // If I do it using the storyboard code below, the animation has no effect
  Storyboard.SetTarget(blurEffectAnimation, Marker.Effect);
  Storyboard.SetTargetProperty(blurEffectAnimation, 
                               new PropertyPath(BlurEffect.RadiusProperty));

  Storyboard sb=new Storyboard();

  sb.Children.Add(blurEffectAnimation);
  sb.Begin();

有趣的是,如果我以姓名登记并用该名字在故事板上登记,效果就会再次出现:

  // Register the MarketBlurEffect (as it s named in the XAML) effect by name 
  // with the FrameworkElement being animated (why do I need to?)
  Marker.RegisterName("MarkerBlurEffect",MarkerBlurEffect);

  // Instead of SetTarget, use SetTargetName on the registered name
  Storyboard.SetTargetName(blurEffectAnimation, "MarkerBlurEffect");
  Storyboard.SetTargetProperty(blurEffectAnimation, 
    new PropertyPath(BlurEffect.RadiusProperty));

  Storyboard sb=new Storyboard();

  sb.Children.Add(blurEffectAnimation);
  // Provide Marker to the Begin function in order to specify the name scope 
  // for the registered ("MarkerBlurEffect") name. Not doing this will result
  // in an InvalidOperationException with the Message property set to:
  //   No applicable name scope exists to resolve the name  MarkerBlurEffect .
  sb.Begin(Marker);
问题回答

页: 1 由于埃夫德目标在树林中很深,你必须这样做。 或者,你可以听从你的影响,把你的财产道路改变成像:

DoubleAnimation blurEffectAnimation = new DoubleAnimation
{
  From = 0,
  To = 10,
  Duration = TimeSpan.FromSeconds(2.0)
};

Storyboard.SetTarget(
  blurEffectAnimation, 
  Marker);

Storyboard.SetTargetProperty(
  blurEffectAnimation,
  new PropertyPath("(Effect).Radius"));

Storyboard sb = new Storyboard();

sb.Children.Add(blurEffectAnimation);
sb.Begin();




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签