• 制作圆角文本框与圆角按钮


    决定控件外观的是ControlTemplate,它决定了控件“长成什么样子”,是控件的外衣。因此,可以通过设计ControlTemplate,制作
    圆角文本框与圆角按钮。
    <Window x:Class="ArtStudio.TemplateDemo"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="TemplateDemo" Height="300" Width="300">
        <Window.Resources>
            <ControlTemplate  x:Key="CornerButton" TargetType="{x:Type Button}">
                <Border BorderBrush="Green" BorderThickness="1" CornerRadius="10" Background="Red">
                    <ContentPresenter Content="{TemplateBinding ContentControl.Content}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                </Border>
            </ControlTemplate>
            <ControlTemplate  x:Key="CornerTextBox" TargetType="{x:Type TextBox}">
                <Border BorderBrush="Blue" BorderThickness="1" CornerRadius="10" Background="#FFD5F0D4">
                    <ScrollViewer x:Name="PART_ContentHost" VerticalAlignment="Center"/>
                </Border>
            </ControlTemplate>
        </Window.Resources>
        <Canvas>
            <Button x:Name="btnOK" Content="OK" Template="{StaticResource CornerButton}" Height="26" Canvas.Top="175" Width="61" Canvas.Left="58" Click="btnOK_Click"></Button>
            <Button x:Name="btnCancel" Content="Cancel" Template="{StaticResource CornerButton}" Height="26" Canvas.Top="175" Width="61" Canvas.Left="138"></Button>
            <TextBox Template="{StaticResource CornerTextBox}" Canvas.Left="74" Canvas.Top="50" Height="23" Name="textBox1" Width="120" Background="#FF7FBC7D" />
            <TextBox Template="{StaticResource CornerTextBox}" Canvas.Left="74" Canvas.Top="108" Height="23" Name="textBox2" Width="120" />
        </Canvas>
    </Window>

    效果如图:

  • 相关阅读:
    LeetCode. 476. Number Complement
    LeetCode 172.Factorial Trailing Zeroes
    原码,反码,补码笔记
    python3笔记
    django笔记(python web框架)
    mysql 8.0 主从复制配置
    centos 7系统安装mysql 8.0
    MobaXterm无法退格删除
    Oracle数据泵常用命令
    oracle查年度周末日期
  • 原文地址:https://www.cnblogs.com/zhouhb/p/3284780.html
Copyright © 2020-2023  润新知