WPF做一个闪动的按钮

来源:互联网 发布:less没网络可以安装吗 编辑:程序博客网 时间:2024/06/16 00:23

xaml代码:

<Button Name="_btn" Width="20" Visibility="Visible" Height="20" HorizontalAlignment="Left" Template="{DynamicResource ButtonControlTemplate}" Cursor="Hand"    Margin="20,0,0,0">
                    <Button.Resources>
                        <ControlTemplate x:Key="ButtonControlTemplate" TargetType="{x:Type Button}">
                            <Grid>
                                <Ellipse x:Name="ButtonEllipse" Width="Auto" Height="Auto" StrokeThickness="2" Fill="Gray" Stroke="Gray"></Ellipse>
                                <Polygon x:Name="ButtonPolygon" Stretch="Fill"  Stroke="Gray" StrokeThickness="1">
                                    <Polygon.Fill>
                                        <SolidColorBrush Color="Red" Opacity="0.4"/>
                                    </Polygon.Fill>
                                </Polygon>
                            </Grid>
                        </ControlTemplate>
                    </Button.Resources>
                </Button>


C#代码:

           将该代码放在一个定时事件中响应,

            Ellipse rec = (Ellipse)_btn.Template.FindName("ButtonEllipse", _btn);
            if (rec.Fill == System.Windows.Media.Brushes.Gray)
            {
                rec.Fill = System.Windows.Media.Brushes.LightGreen;
            }
            else
            {
                rec.Fill = System.Windows.Media.Brushes.Gray;
            }

0 0