WPF登录注册学习

前端后端代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfMVVM.ViewModel;

namespace WpfMVVM.View
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new UserViewModel();
        }
    }
}

 【第一部分】

 <前端代码>

<Grid.RowDefinitions>
            <RowDefinition Height="5*"/>
            <RowDefinition Height="3*"/>
            <RowDefinition Height="1.5*"/>
        </Grid.RowDefinitions>
        <DataGrid x:Name="dgUser" IsReadOnly="True" AutoGenerateColumns="False" CanUserAddRows="False" HorizontalAlignment="Left" ItemsSource="{Binding UserList}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged" >
                    <i:InvokeCommandAction Command="{Binding SelectionCommand}" CommandParameter="{Binding ElementName=dgUser}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding ID}" Header="编号"/>
                <DataGridTextColumn Binding="{Binding Name}" Header="姓名" Width="100"/>
                <DataGridTextColumn Binding="{Binding Age}" Header="年龄"/>
                <DataGridTextColumn Binding="{Binding Sex}" Header="性别" Width="60"/>
                <DataGridTextColumn Binding="{Binding Address}" Header="地址" Width="172"/>
            </DataGrid.Columns>
        </DataGrid>

【第二部分】

<前端代码>

   <GroupBox Header="用户基本信息" Grid.Row="1">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal">
                    <Label x:Name="lblID" Content="编号:" VerticalAlignment="Center" />
                    <TextBox x:Name="tbxID" IsEnabled ="False"  Text="{Binding SelectUser.ID}" VerticalAlignment="Center" MaxLength="5" Height="22"  Width="90"/>
                </StackPanel>
                <StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal">
                    <Label x:Name="lblName"  Content="姓名:" VerticalAlignment="Center" />
                    <TextBox x:Name="tbxName" Text="{Binding SelectUser.Name}" VerticalAlignment="Center" Height="22" MaxLength="6" Width="90"/>
                </StackPanel>
                <StackPanel Grid.Column="2" Grid.Row="0" Orientation="Horizontal">
                    <Label x:Name="lblAge" Content="年龄:" VerticalAlignment="Center" />
                    <TextBox x:Name="tbxAge" Text="{Binding SelectUser.Age}" VerticalAlignment="Center" Height="22" MaxLength="4" Width="90"/>
                </StackPanel>
                <StackPanel Grid.Column="0" Grid.Row="1" Orientation="Horizontal">
                    <Label x:Name="lblSex" Content="性别:" VerticalAlignment="Center"/>
                    <ComboBox Text="{Binding SelectUser.Sex}"  SelectedIndex="0" x:Name="cbxSex" VerticalAlignment="Center"  Width="90">
                        <ComboBoxItem Tag="1" Content="男"/>
                        <ComboBoxItem Tag="2" Content="女"/>
                    </ComboBox>
                </StackPanel>
                <StackPanel  Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="2" Orientation="Horizontal">
                    <Label x:Name="lblRemarks" Content="地址:" VerticalAlignment="Center"/>
                    <TextBox x:Name="tbxRemarks" Text="{Binding SelectUser.Address}" VerticalAlignment="Center" Height="22" Width="235" />
                </StackPanel>
            </Grid>

【第三部分】

<前端代码>

 <GroupBox Header="功能操作" Grid.Row="2">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                <Button x:Name="btnSave" Command="{Binding AddCommand}" Content="新增" VerticalAlignment="Center"  Width="69" Height="19" Margin="10,0,10,0" />
                <Button x:Name="btnUpdate" Command="{Binding UpdateCommand}" Content="修改" VerticalAlignment="Center" Width="69" Height="19" Margin="10,0,10,0"/>
                <Button x:Name="btnDelete" Command="{Binding DeleteCommand}" Content="删除" VerticalAlignment="Center" Width="69" Height="19" Margin="10,0,10,0"/>
            </StackPanel>
        </GroupBox>

他没连数据库,伤心了。。。。。。。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值