WPF 设置 圆角 例如Grid、Button、TextBox、PasswordBox

1、背景设置圆角:

<Window x:Class="ESPCPS.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ESPCPS"
        mc:Ignorable="d"
        Title="系统" Height="500" Width="800"  WindowStyle="None"  AllowsTransparency="True" Background="Transparent" OpacityMask="White" ResizeMode="NoResize" MouseMove="Window_MouseMove" >
    <Border BorderThickness="1" BorderBrush="Gray"  CornerRadius="25,25,25,25">
        <Grid Width="800" Margin="0" Height="500"  >
            <Border BorderThickness="0" CornerRadius="25,25,25,25">
                <Border.Background>
                    <ImageBrush ImageSource="beijing.jpg"/>
                </Border.Background>
            </Border>
        </Grid>
    </Border>
</Window>

 2、设置按钮

 直接在XAML里更改

<Button x:Name="but1" Content="软件介绍" HorizontalAlignment="Left" Margin="126,356,0,0" VerticalAlignment="Top" Width="128" Click="Button_Click" FontSize="20" Height="35" >
                <Button.Template>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="1" CornerRadius="10">
                            <Border.Background>#FF8EB4D4</Border.Background>
                            <ContentPresenter Content="{TemplateBinding ContentControl.Content}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Border>
                    </ControlTemplate>
                </Button.Template>
            </Button>

效果如下:

 可能出现的问题:

因为没系统学过如何编写XAML内容,所以在格式上出现了很大的笑话

一直报错就需要检查一下书写问题

比如<Border ……> </Border>

或者<Border ……/>

两种格式都行,不能混用!!!

而且里面的比如背景颜色或者位置啊按钮大小啊都是可以更改的,可以试一试。


3、设置TextBox圆角

<TextBox HorizontalAlignment="Left" Height="24" Margin="43,192,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="98">
                <TextBox.Resources>
                    <Style TargetType="{x:Type Border}">
                        <Setter Property="CornerRadius" Value="8"/>
                        <Setter Property="BorderBrush" Value="#c1d0dc"/>
                    </Style>
                </TextBox.Resources>
            </TextBox>


4、PasswordBox设置圆角

 <PasswordBox x:Name="t2" HorizontalAlignment="Left" Margin="183,150,0,0" VerticalAlignment="Top" Width="114" Height="26" BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" FontSize="18" Password="&#xD;&#xA;">
                <PasswordBox.Resources>
                    <Style TargetType="PasswordBox">
                        <Setter Property="PasswordChar" Value="●"/>
                        <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
                        <Setter Property="HorizontalContentAlignment" Value="Left"/>
                        <Setter Property="Padding" Value="1"/>
                        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                        <Setter Property="AllowDrop" Value="true"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="PasswordBox">
                                    <Border CornerRadius="8" x:Name="Bd" Background="White" BorderBrush="#c1d0dc" BorderThickness="1" OpacityMask="{x:Null}">
                                        <ScrollViewer SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" x:Name="PART_ContentHost" Template="{DynamicResource ScrollViewerControlTemplate1}"/>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </PasswordBox.Resources>
            </PasswordBox>

实现效果

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值