Overriding buttons

I have a button as such:

<Button HorizontalAlignment="Left" Margin="0,55,0,0" VerticalAlignment="Top" Width="350" Click="StartProcedure_Click" BorderThickness="0" Height="60" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" HorizontalContentAlignment="Left" ScrollViewer.VerticalScrollBarVisibility="Disabled" VerticalContentAlignment="Center" Padding="10,1,0,0" IsHitTestVisible="True">
            <StackPanel Orientation="Horizontal">
                <Image Source="resources\img_xraystarticon.png" Width="50" Height="50"/>
                <TextBlock TextElement.Foreground="#6a6869" Padding="5,0,0,0" VerticalAlignment="Center" FontSize="30" FontFamily="Century Gothic">Start Procedure</TextBlock>
            </StackPanel>
            <Button.Background>
                <ImageBrush ImageSource="resources\img_emptyrectbutton.png"/>
            </Button.Background>
        </Button>

      

Where I applied Style = "{StaticResource {x: Static ToolBar.ButtonStyleKey}}" to remove the mouse effects, by default with a button. However, I am still experiencing the mouseover effect as shown below:

enter image description here

Up to the mouse and with the mouse:

enter image description here

I have tried overriding the MouseEnter event without any success (I confirmed that my MouseEnter event was fired, but I cannot nullify the property set with the default MouseEnter above).

What do I need to do to avoid the above?

Thank!

EDIT:

I entered the code below, but now I can't get the MouseEnter function to execute correctly (I want the text to change colors, but I can't see it):

<Button Name="Button_StartMenu" HorizontalAlignment="Left" Margin="0,55,0,0" VerticalAlignment="Top" Width="350" Click="StartProcedure_Click" BorderThickness="0" Height="60" HorizontalContentAlignment="Left" ScrollViewer.VerticalScrollBarVisibility="Disabled" VerticalContentAlignment="Center" Padding="10,1,0,0" IsHitTestVisible="True" MouseEnter="Button_MouseEnter">
            <Button.Background>
                <ImageBrush ImageSource="resources\img_emptyrectbutton.png"/>
            </Button.Background>
            <Button.Style>
                <Style TargetType="{x:Type Button}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Button.Style>
            <StackPanel Orientation="Horizontal">
                <Image Source="resources\img_xraystarticon.png" Width="50" Height="50"/>
                <TextBlock TextElement.Foreground="#6a6869" Padding="5,0,0,0" VerticalAlignment="Center" FontSize="30" FontFamily="Century Gothic"><Run Text="Start Procedure"/></TextBlock>
            </StackPanel>
        </Button>

      

+3


source to share


1 answer


Instead of trying to "prevent" it, I would define a mouseover event to display the same thing without a mouse. You can set both of them to be the same, and while it switches anyway, visually it looks the same.

How can I change the background for a MouseOver button in WPF?



       <Button.Style>
            <Style TargetType="Button">
                <Setter Property="Background" Value="Green"/>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="Green"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Button.Style>

      

+1


source







All Articles