1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > WPF 设置 圆角 例如Grid Button TextBox PasswordBox

WPF 设置 圆角 例如Grid Button TextBox PasswordBox

时间:2024-01-02 04:03:00

相关推荐

WPF 设置 圆角 例如Grid Button TextBox PasswordBox

1、背景设置圆角:

<Window x:Class="ESPCPS.MainWindow"xmlns="/winfx//xaml/presentation"xmlns:x="/winfx//xaml"xmlns:d="/expression/blend/"xmlns:mc="/markup-compatibility/"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>

实现效果

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。