开发者

WPF button flash to white color when I Click

开发者 https://www.devze.com 2023-02-10 07:17 出处:网络
I just created the wpf button and whenI click on the button, it changed to white color like flashing and change back to original color when I release the button. What could be the problem? I didn\'t u

I just created the wpf button and when I click on the button, it changed to white color like flashing and change back to original color when I release the button. What could be the problem? I didn't use any effect. Below is my button xaml. please advice.

<Button Content="ROM" Height="121" HorizontalAlignment="Left" Margin="91,269,0,0" Name="button1" VerticalAlignment="Top" Width="566" FontSize开发者_C百科="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>


One method is to place a transparent button on top of an image that looks like a button, then set the button's opacity value to zero.

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


This is becuase of the default ButtonChrome. if you extract the default details from Expression blend of the button

<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 is setting the effect. If you want to remove or modify the effects you have to create your own controltemplate or style

0

精彩评论

暂无评论...
验证码 换一张
取 消