WPF学习记录 三、控件模版

可以给控件增加模版样式

如下就把一个按钮,完成变成了其它的样式:

    <Window.Resources>
        <ControlTemplate  x:Key="myTemplate" TargetType="Button">
            <Border Background="Red" CornerRadius="5">
                <StackPanel Orientation="Horizontal" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                    <TextBlock Text="$" VerticalAlignment="Center"></TextBlock>
                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}"></ContentPresenter>
                </StackPanel>
            </Border>
        </ControlTemplate>
    </Window.Resources>
    <Grid>
        <DockPanel  LastChildFill="False">
            <Button DockPanel.Dock="Left" Height="50" Width="100" Template="{StaticResource myTemplate}" HorizontalAlignment="Center" VerticalAlignment="Center"  Content="确定"></Button>
        </DockPanel>
    </Grid>

原文地址:https://www.cnblogs.com/wjx-blog/p/15423550.html