none
blinking blue 这个玩艺怎么用代码给Polygon的stroke,也就是边框赋值上呢? RRS feed

  • 问题

  • 大家好,有个需求,某个条件满足时polygon的边框需要有闪烁的蓝色表示,在后代码中怎么实现呢?

    嘿嘿,不容易呀。

    2011年10月31日 9:00

答案

  • 参考我的例子:

    <Grid Name="SetBackGrid">
        <Path Name="SetBackPath" Margin="5" Data="M 5,6 14,6 14,12 5,12 z" Stretch="Fill" StrokeThickness="5">
            <Path.Stroke>
                <SolidColorBrush Color="Blue"/>
            </Path.Stroke>
        </Path>
        <Button Width="50" Height="50" Click="Button_Click"/>
    </Grid>
    

    Code-Behind:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        NameScope.SetNameScope(SetBackGrid, new NameScope());
        Storyboard board =new Storyboard();
        ColorAnimation coloranim =new ColorAnimation();
        coloranim.Duration =new TimeSpan(0, 0, 0, 0, 500);
        coloranim.AutoReverse = true;
        coloranim.RepeatBehavior = RepeatBehavior.Forever;
        coloranim.To = Colors.White;
        coloranim.SetValue(Storyboard.TargetProperty, SetBackPath);
        coloranim.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("Stroke.Color"));
        board.Children.Add(coloranim);
        board.Begin(SetBackPath);
    }
    

    根据这个例子改成你需要的就行了。

     

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年11月2日 6:47
    版主

全部回复

  • 再具体点说,我想让边框stroke白色和蓝色之间相互转变每隔半秒
    2011年10月31日 10:24
  • 参考我的例子:

    <Grid Name="SetBackGrid">
        <Path Name="SetBackPath" Margin="5" Data="M 5,6 14,6 14,12 5,12 z" Stretch="Fill" StrokeThickness="5">
            <Path.Stroke>
                <SolidColorBrush Color="Blue"/>
            </Path.Stroke>
        </Path>
        <Button Width="50" Height="50" Click="Button_Click"/>
    </Grid>
    

    Code-Behind:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        NameScope.SetNameScope(SetBackGrid, new NameScope());
        Storyboard board =new Storyboard();
        ColorAnimation coloranim =new ColorAnimation();
        coloranim.Duration =new TimeSpan(0, 0, 0, 0, 500);
        coloranim.AutoReverse = true;
        coloranim.RepeatBehavior = RepeatBehavior.Forever;
        coloranim.To = Colors.White;
        coloranim.SetValue(Storyboard.TargetProperty, SetBackPath);
        coloranim.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("Stroke.Color"));
        board.Children.Add(coloranim);
        board.Begin(SetBackPath);
    }
    

    根据这个例子改成你需要的就行了。

     

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年11月2日 6:47
    版主