单击时,WPF按钮闪烁为白色

时间:2011-02-15 08:37:41

标签: wpf

我刚创建了wpf按钮,当我点击按钮时,它变为白色,如闪烁,当我松开按钮时,它会变回原来的颜色。可能是什么问题呢?我没有使用任何效果。下面是我的按钮xaml。请指教。

<Button Content="ROM" Height="121" HorizontalAlignment="Left" Margin="91,269,0,0" Name="button1" VerticalAlignment="Top" Width="566" FontSize="48" BorderBrush="#FF3DFF00" BorderThickness="10" Foreground="White">
            <Button.BitmapEffect>
                <DropShadowBitmapEffect ShadowDepth="2" Color="Gray"></DropShadowBitmapEffect>
            </Button.BitmapEffect>
            <Button.Background>
                <RadialGradientBrush>
                    <GradientStop Color="#FF4094D8" Offset="0" />
                    <GradientStop Color="#FF2B476F" Offset="1" />
                </RadialGradientBrush>
            </Button.Background>
        </Button>

2 个答案:

答案 0 :(得分:2)

一种方法是在看起来像按钮的图像上放置一个透明按钮,然后将按钮的不透明度值设置为零。

<Image Name="buttonImage1" Source="../Images/infoButton.png" Grid.Row="1"/>
<Button Name="infoButton" Tap="infoButton_Tap" Opacity="0.0" BorderBrush="Transparent" Grid.Row="1"/>

答案 1 :(得分:1)

这是默认的ButtonChrome。如果从按钮的表达式混合中提取默认详细信息

<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
        <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
        <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
        <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Padding" Value="1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" RenderDefaulted="{TemplateBinding IsDefaulted}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}">
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True"/>
                    </Microsoft_Windows_Themes:ButtonChrome>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsKeyboardFocused" Value="true">
                            <Setter Property="RenderDefaulted" TargetName="Chrome" Value="true"/>
                        </Trigger>
                        <Trigger Property="ToggleButton.IsChecked" Value="true">
                            <Setter Property="RenderPressed" TargetName="Chrome" Value="true"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="#ADADAD"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

Microsoft_Windows_Themes:ButtonChrome正在设置效果。如果要删除或修改效果,您必须创建自己的controltemplate或样式