문제

I am using below mentioned Style to change the style of my button. Everything is as expected however the scope of my "IsMouseOver" is only till the written content inside the button, not after that. So if I hover over written content , it gets triggered only then and NOT if I hover anywhere in the whole button. Why so ?

    <Style x:Key="fancyButton" TargetType="Button">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="Foreground" Value="Navy"/>
        <Setter Property="Height" Value="25"/>
        <Setter Property="Width" Value="150"/>
        <Setter Property="Margin" Value="10"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid x:Name="grid">
                        <Border x:Name="border" CornerRadius="3" BorderBrush="Transparent" BorderThickness="2">
                            <ContentPresenter HorizontalAlignment="Left" VerticalAlignment="Center"></ContentPresenter>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" TargetName="border" Value="#d9e2f1"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>
도움이 되었습니까?

해결책

Set Background of a Border (or Grid) to Transparent instead of default null

<Border x:Name="border" Background="Transparent" ...>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top