具有自定义外观和故事板的WPF C#按钮样式

时间:2018-02-02 16:04:51

标签: c# wpf storyboard controltemplate

我有两个问题:

  1. 我想创建一个Button,其中Border在MouseEnter上逆时针出现,并在MouseLeave上顺时针消失。 在IsMouseOver,IsPressed和IsDefault模式下,按钮的背景是透明的。现在我想把它变成一个动态资源样式,所以我不必在Button部分创建像一百个矩形。 这是我到目前为止硬编码的部分:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            主要                      

  2. 和Style部分:

    <Style x:Key="ButtonNavBarPages" TargetType="Button">
    
                <Setter Property="SnapsToDevicePixels" Value="True" />
                <Setter Property="OverridesDefaultStyle" Value="True" />
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="BorderBrush" Value="Transparent"/>
                <Setter Property="BorderThickness" Value="0"/>
                <Setter Property="Foreground" Value="#FF494949"/>
                <Setter Property="Width" Value="200"/>
                <Setter Property="FontSize" Value="14" />
                <Setter Property="FontFamily" Value="Calibri Light" />
                <Setter Property="Margin" Value="0 2"/>
    
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="Transparent"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="Button">
                                    <Border Background="{TemplateBinding Background}" BorderBrush="Transparent" BorderThickness="0" CornerRadius="0">
                                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter Property="Background" Value="Transparent"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="Button">
                                    <Border Background="{TemplateBinding Background}" BorderBrush="Transparent" BorderThickness="0" CornerRadius="0">
                                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="IsDefault" Value="True">
                        <Setter Property="Background" Value="Transparent"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="Button">
                                    <Border Background="{TemplateBinding Background}" BorderBrush="Transparent" BorderThickness="0" CornerRadius="0">
                                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>
    
    1. 我还想创建一个Button,它将IsMouseOver上的Background设置为LightGray,还将Foreground设置为White。我到目前为止所尝试的一切都没有成功......
    2. 我真的很期待你的回答!

0 个答案:

没有答案