在XAML WPF中简单地设置按钮样式?

时间:2013-10-27 18:33:35

标签: wpf xaml button

我一直在尝试在XAML WPF中设置一个按钮,但经过一段时间的搜索后,我仍然无法找到一个简单易用的解决方案。

我将如何在HTML&amp;中设置我的链接<a>Button</a>。 CSS:

a{   
    display: inline-block;    
    border-top: 1px solid #363636;   
    border-bottom: 1px solid #121212;  
    border-right: 1px solid #121212;  
    border-left: 1px solid #363636;  
    background: #282828;  
    padding: 0 0 0 25px;  
    width: 165px;  
    line-height: 25px;  
    font-size: 13px;  
    text-decoration: none;  
    color: #ebebeb;  
    text-shadow: 0 1px 1px #121212;  
}

P.S。无法发布图片。您可以看到按钮here (JSFiddle)

1 个答案:

答案 0 :(得分:1)

我不熟悉所有CSS属性,但您可以覆盖它的ControlTemplate,如下所示:

    <Style TargetType="{x:Type Button}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border BorderThickness="1,0,0,0" Width="165">
                        <Border.BorderBrush>
                            <SolidColorBrush Color="#363636"/>
                        </Border.BorderBrush>
                        <Border BorderThickness="0,1,0,0">
                            <Border.BorderBrush>
                                <SolidColorBrush Color="#363636"/>
                            </Border.BorderBrush>
                            <Border BorderThickness="0,0,1,0">
                                <Border.BorderBrush>
                                    <SolidColorBrush Color="#121212"/>
                                </Border.BorderBrush>
                                <Border BorderThickness="0,0,0,1">
                                    <Border.BorderBrush>
                                        <SolidColorBrush Color="#121212"/>
                                    </Border.BorderBrush>
                                    <TextBlock Text="{TemplateBinding Content}"
                                               FontSize="13"
                                               Width="165"
                                               Padding="25,0,0,0">
                                        <TextBlock.Foreground>
                                            <SolidColorBrush Color="#ebebeb"/>
                                        </TextBlock.Foreground>
                                        <TextBlock.Background>
                                            <SolidColorBrush Color="#282828"/>
                                        </TextBlock.Background>
                                        <TextBlock.Effect>
                                            <DropShadowEffect Color="#121212"/>
                                        </TextBlock.Effect>
                                    </TextBlock>
                                </Border>
                            </Border>
                        </Border>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

然而,这有点像黑客,但我认为这正是你要找的。但是,如果你想这样做,你应该研究creating your own decorator

希望这有帮助