按钮缩放椭圆,按钮不可点击

时间:2010-05-09 16:47:06

标签: wpf c#-3.0 button wpf-controls ellipse

我正在使用以下代码缩放动画中的椭圆:

        ScaleTransform myScTransform = new ScaleTransform();
        TransformGroup myTransGroup = new TransformGroup();
        myTransGroup.Children.Add(myScTransform);
        newPHRadio.RenderTransform = myTransGroup;
        newPHRadio.RenderTransformOrigin = new Point(0.5, 0.5);

        Storyboard story = new Storyboard();
        DoubleAnimation xAnimation = new DoubleAnimation(1, ph.Bereik, new Duration(TimeSpan.FromSeconds(2)));
        DoubleAnimation yAnimation = new DoubleAnimation(1, ph.Bereik, new Duration(TimeSpan.FromSeconds(2)));
        DoubleAnimation doorzichtig = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(2)));

        Storyboard.SetTarget(xAnimation, newPHRadio);
        Storyboard.SetTarget(yAnimation, newPHRadio);
        Storyboard.SetTarget(doorzichtig, newPHRadio);

        DependencyProperty[] propertyChainX = new DependencyProperty[] {
           Ellipse.RenderTransformProperty, 
           TransformGroup.ChildrenProperty,
           ScaleTransform.ScaleXProperty
        };

        DependencyProperty[] propertyChainY = new DependencyProperty[] {
           Ellipse.RenderTransformProperty, 
           TransformGroup.ChildrenProperty,
           ScaleTransform.ScaleYProperty
        };

        string thePath = "(0).(1)[0].(2)";

        Storyboard.SetTargetProperty(xAnimation, new PropertyPath(thePath, propertyChainX));
        Storyboard.SetTargetProperty(yAnimation, new PropertyPath(thePath, propertyChainY));
        Storyboard.SetTargetProperty(doorzichtig, new PropertyPath(Ellipse.OpacityProperty));

        story.Children.Add(xAnimation);
        story.Children.Add(yAnimation);
        story.Children.Add(doorzichtig);

        story.Duration = new Duration(TimeSpan.FromSeconds(60 / ph.Frequentie));
        story.RepeatBehavior = RepeatBehavior.Forever;
        story.Begin();

使用以下代码构造椭圆:

        Ellipse newPHRadio = new Ellipse();

        newPHRadio.Width = 1;
        newPHRadio.Height = 1;
        newPHRadio.SetValue(Canvas.LeftProperty, ph.xPositie + 7);
        newPHRadio.SetValue(Canvas.TopProperty, ph.yPositie + 7);
        newPHRadio.SetValue(Canvas.ZIndexProperty, 3);

        newPHRadio.Stroke = new SolidColorBrush(Colors.Black);
        newPHRadio.StrokeThickness = 0.03;

现在,椭圆在z-index为1的按钮上缩放。对于静态椭圆并且没有填充,按钮是可单击的。现在也没有填充,但按钮不可点击。有人能告诉我如何解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

使用您提供的代码,该按钮是可点击的。

但是如果将椭圆的填充设置为除null之外的任何值,甚至是Brushes.Transparent,则单击将不再使其成为按钮。

尝试将椭圆的填充显式设置为null:

newPHRadio.Fill = null;