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>

 

posted @ 2021-10-24 15:06  星星c#  阅读(60)  评论(0编辑  收藏  举报