WPF去掉边框及设置圆角框

本文介绍了如何在WPF中去掉窗体边框,实现窗体不可手动改变大小,以及在无边框情况下实现窗体拖动。同时,讲解了如何为文本框和密码框设置圆角边框,详细讲述了XAML中的相关配置和代码实现。

去掉窗体边框

<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>
评论 10
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值