欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

WPF去掉边框及设置圆角框

程序员文章站 2022-07-14 12:30:50
...

去掉窗体边框

<windows WindowStyle="None"  AllowsTransparency="True"></windows>

设置窗体不可手动改变大小

<windows ResizeMode=NoResize></windows>

窗体无边框时拖动窗体

  • 在XAML中写入MouseMove事件
<Window x:Class="Gvitech.Application.WPF.UI.FunFacility.WindowEquipmentRecord"
 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 
        Title="WindowTest" Height="360" Width="680" WindowStyle="None"  
 
        WindowState="Normal" AllowsTransparency="True" MouseMove="window_MouseMove" >
  • 在代码中实现MouseMove事件
private void Window_MouseMove(object sender, MouseEventArgs e)
{
    if (e.LeftButton == MouseButtonState.Pressed)

    {

        this.DragMove();

    }
}

文本框设置圆角边框

<Border Margin="435,135,435,492" CornerRadius="10" Background="Gray">
    <TextBox BorderThickness="0" Background="Transparent"  Text="ID" VerticalAlignment="Center" FontSize="13" Margin="18.2,8.2,8,-1.4" Foreground="White"  Height="22" RenderTransformOrigin="0.489,0.259"></TextBox>
</Border>

密码框设置圆角边框

//在App.xaml中添加:
<Application.Resources>
    <Style TargetType="PasswordBox">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="PasswordBox">
                    <Grid>
                        <Rectangle RadiusX="10" RadiusY="10" Fill="{TemplateBinding Background}" Stroke="#7e94a9"/>
                        <ScrollViewer SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" x:Name="PART_ContentHost" Template="{DynamicResource ScrollViewerControlTemplate1}"  />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Application.Resources>
相关标签: WPF圆角框