WPF 项目实例

本文介绍如何在WPF项目中快速创建表格,通过Grid.RowDefinitions和Grid.ColumnDefinitions进行行列划分,调整Width和Height控制大小。利用Grid.Column和Grid.Row定位元素,以及Grid.ColumnSpan和Grid.RowSpan实现跨行跨列。还分享了一个设计页面的小技巧,按空格键拖拽和使用鼠标快速创建行列。最后展示了完成后的效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

开发工具与关键技术:Visual Studio

今天教大家用WPF做window窗口快速创建表格;
下面我们来看一下代码,

<Window x:Class="Client.View.Order_editing"
        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:Client.View"
        Icon="/Icon/icon.png" 
        Title="订单编辑"  Height="500" Width="1100" 
        WindowStartupLocation="CenterScreen" 
        ResizeMode="NoResize" 
        BorderThickness="1" BorderBrush="White" Background="White" >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="49*"/>
            <RowDefinition Height="25*"/>
            <RowDefinition Height="40*"/>
            <RowDefinition Height="40*"/>
            <RowDefinition Height="40*"/>
            <RowDefinition Height="40*"/>
            <RowDefinition Height="40*"/>
            <RowDefinition Height="40*"/>
            <RowDefinition Height="80*"/>
            <RowDefinition Height="40*"/>
            <RowDefinition Height="20*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1.4*"/>
            <ColumnDefinition Width="1.15*"/>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="1*"/>
        </Grid.ColumnDefinitions>

        <Border Width="1080" Height="458" HorizontalAlignment="Center" VerticalAlignment="Top" CornerRadius="15" Grid.RowSpan="11" Grid.ColumnSpan="4">
            <Border.Background>
                <ImageBrush ImageSource="/Client;component/images/upbei.png"/>
            </Border.Background>
        </Border>

        <Border BorderThickness="1" BorderBrush="Gray"  CornerRadius="15,15,15,15" Grid.ColumnSpan="4" Grid.RowSpan="11" />
        <Border BorderThickness="0 0 0 2" Width="1080" Height="50" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,1,0,0" CornerRadius="15,15,0,0" Grid.ColumnSpan="4" BorderBrush="Gray">
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FF7AB4FB" Offset="0.992"/>
                    <GradientStop Color="#FFC8FCFF"/>
                    <GradientStop Color="#FF83BCFB" Offset="0.94"/>
                    <GradientStop Color="#FFB9EEFE" Offset="0.193"/>
                </LinearGradientBrush>
            </Border.Background>
        </Border>

        <Button Name="btn_xinzeng" Content="新增" Height="30" Width="60" FontSize="16" Cursor="Hand" Foreground="Black" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="20,10,0,0" Padding="2" BorderBrush="{x:Null}">
            <Button.Background>
                <ImageBrush ImageSource="/Client;component/Icon/anniu.png"/>
            </Button.Background>
        </Button>

        <Button Name="btn_xiugai" Content="保存" Height="30" Width="60" FontSize="16" Cursor="Hand" Foreground="Black" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="100,10,0,0" Padding="2" BorderBrush="{x:Null}">
            <Button.Background>
                <ImageBrush ImageSource="/Client;component/Icon/anniu.png"/>
            </Button.Background>
        </Button>

        <Button Name="btn_dayin" Content="打印" Height="30" Width="60" FontSize="16" Cursor="Hand" Foreground="Black" 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值