精华内容
下载资源
问答
  • WPF开发实例——仿QQ登录界面 原文:WPF开发实例——仿QQ登录界面 版权声明:本文为博主原创文章,如需转载请标明转载地址 ...
    原文:WPF开发实例——仿QQ登录界面

    版权声明:本文为博主原创文章,如需转载请标明转载地址 http://blog.csdn.net/u013981858 https://blog.csdn.net/u013981858/article/details/49130885

    刚开始学WPF,自己写了个小东西,说实话写的并不好,好多东西不懂只是用现在懂的东西来写的,效果如图

    下面是源码,理论上很简单,我直接放代码了。

    自定义用户控件RightButton.xaml

    <UserControl x:Class="WpfApplication8.RigthButton"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 mc:Ignorable="d" 
                 d:DesignHeight="300" d:DesignWidth="300">
        <UserControl.Resources>
            <Style x:Key="CloseButton" TargetType="{x:Type Button}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Button}">
                            <Grid>
                                <Rectangle x:Name="rectangle">
                                    <Rectangle.Fill>
                                        <ImageBrush ImageSource="skin/close_normal.png"/>
                                    </Rectangle.Fill>
                                </Rectangle>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsFocused" Value="True"/>
                                <Trigger Property="IsDefaulted" Value="True"/>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Fill" TargetName="rectangle">
                                        <Setter.Value>
                                            <ImageBrush ImageSource="skin/close_hot.png"/>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter Property="Fill" TargetName="rectangle">
                                        <Setter.Value>
                                            <ImageBrush ImageSource="skin/close_down.png"></ImageBrush>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False"/>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    
            <Style x:Key="SmallButton" TargetType="{x:Type Button}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Button}">
                            <Grid>
                                <Rectangle x:Name="rectangle">
                                    <Rectangle.Fill>
                                        <ImageBrush ImageSource="skin/small_normal.png"/>
                                    </Rectangle.Fill>
                                </Rectangle>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsFocused" Value="True"/>
                                <Trigger Property="IsDefaulted" Value="True"/>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Fill" TargetName="rectangle">
                                        <Setter.Value>
                                            <ImageBrush ImageSource="skin/small_hot.png"/>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter Property="Fill" TargetName="rectangle">
                                        <Setter.Value>
                                            <ImageBrush ImageSource="skin/small_down.png"></ImageBrush>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False"/>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    
            <Style x:Key="DownButton" TargetType="{x:Type Button}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Button}">
                            <Grid>
                                <Rectangle x:Name="rectangle">
                                    <Rectangle.Fill>
                                        <ImageBrush ImageSource="skin/down_normal.png"/>
                                    </Rectangle.Fill>
                                </Rectangle>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsFocused" Value="True"/>
                                <Trigger Property="IsDefaulted" Value="True"/>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Fill" TargetName="rectangle">
                                        <Setter.Value>
                                            <ImageBrush ImageSource="skin/down_hot.png"/>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter Property="Fill" TargetName="rectangle">
                                        <Setter.Value>
                                            <ImageBrush ImageSource="skin/down_down.png"></ImageBrush>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False"/>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </UserControl.Resources>
        <StackPanel Orientation="Horizontal">
            <Button Click="Button_Click" Width="30" Height="30" Style="{StaticResource DownButton}"></Button>
            <Button Click="Button_Click_1" Width="30" Height="30" Style="{StaticResource SmallButton}"></Button>
            <Button Click="Button_Click_2" Width="30" Height="30" Style="{StaticResource CloseButton}"></Button>
        </StackPanel>
    </UserControl>
    
    RightButton.xmal.cs

    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.Navigation;
    using System.Windows.Shapes;
    
    namespace WpfApplication8
    {
        /// <summary>
        /// RigthButton.xaml 的交互逻辑
        /// </summary>
        public partial class RigthButton : UserControl
        {
            public RigthButton()
            {
                InitializeComponent();
            }
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
    
            }
    
            private void Button_Click_1(object sender, RoutedEventArgs e)
            {
                
            }
    
            private void Button_Click_2(object sender, RoutedEventArgs e)
            {
                Application.Current.Shutdown();
            }
        }
    }
    
    MainWindow.xaml

    <Window x:Class="WpfApplication8.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:loc="clr-namespace:WpfApplication8"
            Title="企鹅球球" Height="330" Width="430" AllowsTransparency="True" WindowStyle="None" MouseDown="Window_MouseDown">
    	<Window.Resources>
    		<Style x:Key="FocusVisual">
    			<Setter Property="Control.Template">
    				<Setter.Value>
    					<ControlTemplate>
    						<Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    		<SolidColorBrush x:Key="Button.Static.Background" Color="#FFDDDDDD"/>
    		<SolidColorBrush x:Key="Button.Static.Border" Color="#FF707070"/>
    		<SolidColorBrush x:Key="Button.MouseOver.Background" Color="#FFBEE6FD"/>
    		<SolidColorBrush x:Key="Button.MouseOver.Border" Color="#FF3C7FB1"/>
    		<SolidColorBrush x:Key="Button.Pressed.Background" Color="#FFC4E5F6"/>
    		<SolidColorBrush x:Key="Button.Pressed.Border" Color="#FF2C628B"/>
    		<SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4"/>
    		<SolidColorBrush x:Key="Button.Disabled.Border" Color="#FFADB2B5"/>
    		<SolidColorBrush x:Key="Button.Disabled.Foreground" Color="#FF838383"/>
    		<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
    			<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
    			<Setter Property="Background" Value="{StaticResource Button.Static.Background}"/>
    			<Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}"/>
    			<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    			<Setter Property="BorderThickness" Value="1"/>
    			<Setter Property="HorizontalContentAlignment" Value="Center"/>
    			<Setter Property="VerticalContentAlignment" Value="Center"/>
    			<Setter Property="Padding" Value="1"/>
    			<Setter Property="Template">
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type Button}">
    						<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
    							<ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
    						</Border>
    						<ControlTemplate.Triggers>
    							<Trigger Property="IsDefaulted" Value="true">
    								<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
    							</Trigger>
    							<Trigger Property="IsMouseOver" Value="true">
    								<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.MouseOver.Border}"/>
    								<Setter Property="Background" TargetName="border" Value="#FF51B3EC"/>
    							</Trigger>
    							<Trigger Property="IsPressed" Value="true">
    								<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Pressed.Border}"/>
    								<Setter Property="Background" Value="#FF3FA4E8"/>
    								<Setter Property="Background" TargetName="border" Value="#FF42B5F0"/>
    							</Trigger>
    							<Trigger Property="IsEnabled" Value="false">
    								<Setter Property="Background" TargetName="border" Value="{StaticResource Button.Disabled.Background}"/>
    								<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Disabled.Border}"/>
    								<Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/>
    							</Trigger>
    						</ControlTemplate.Triggers>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    		<SolidColorBrush x:Key="OptionMark.Static.Background" Color="#FFFFFFFF"/>
    		<SolidColorBrush x:Key="OptionMark.Static.Border" Color="#FF707070"/>
    		<Style x:Key="OptionMarkFocusVisual">
    			<Setter Property="Control.Template">
    				<Setter.Value>
    					<ControlTemplate>
    						<Rectangle Margin="14,0,0,0" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    		<SolidColorBrush x:Key="OptionMark.MouseOver.Background" Color="#FFF3F9FF"/>
    		<SolidColorBrush x:Key="OptionMark.MouseOver.Border" Color="#FF5593FF"/>
    		<SolidColorBrush x:Key="OptionMark.MouseOver.Glyph" Color="#FF212121"/>
    		<SolidColorBrush x:Key="OptionMark.Disabled.Background" Color="#FFE6E6E6"/>
    		<SolidColorBrush x:Key="OptionMark.Disabled.Border" Color="#FFBCBCBC"/>
    		<SolidColorBrush x:Key="OptionMark.Disabled.Glyph" Color="#FF707070"/>
    		<SolidColorBrush x:Key="OptionMark.Pressed.Background" Color="#FFD9ECFF"/>
    		<SolidColorBrush x:Key="OptionMark.Pressed.Border" Color="#FF3C77DD"/>
    		<SolidColorBrush x:Key="OptionMark.Pressed.Glyph" Color="#FF212121"/>
    		<SolidColorBrush x:Key="OptionMark.Static.Glyph" Color="#FF212121"/>
    		<Style x:Key="CheckBoxStyle1" TargetType="{x:Type CheckBox}">
    			<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
    			<Setter Property="Background" Value="{StaticResource OptionMark.Static.Background}"/>
    			<Setter Property="BorderBrush" Value="{StaticResource OptionMark.Static.Border}"/>
    			<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    			<Setter Property="BorderThickness" Value="1"/>
    			<Setter Property="Template">
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type CheckBox}">
    						<Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True">
    							<Grid.ColumnDefinitions>
    								<ColumnDefinition Width="Auto"/>
    								<ColumnDefinition Width="*"/>
    							</Grid.ColumnDefinitions>
    							<Border x:Name="checkBoxBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
    								<Grid x:Name="markGrid">
    									<Path x:Name="optionMark" Data="F1 M 9.97498,1.22334L 4.6983,9.09834L 4.52164,9.09834L 0,5.19331L 1.27664,3.52165L 4.255,6.08833L 8.33331,1.52588e-005L 9.97498,1.22334 Z " Fill="{StaticResource OptionMark.Static.Glyph}" Margin="1" Opacity="0" Stretch="None"/>
    									<Rectangle x:Name="indeterminateMark" Fill="{StaticResource OptionMark.Static.Glyph}" Margin="2" Opacity="0"/>
    								</Grid>
    							</Border>
    							<ContentPresenter x:Name="contentPresenter" Grid.Column="1" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
    						</Grid>
    						<ControlTemplate.Triggers>
    							<Trigger Property="HasContent" Value="true">
    								<Setter Property="FocusVisualStyle" Value="{StaticResource OptionMarkFocusVisual}"/>
    								<Setter Property="Padding" Value="4,-1,0,0"/>
    							</Trigger>
    							<Trigger Property="IsMouseOver" Value="true">
    								<Setter Property="Background" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.MouseOver.Background}"/>
    								<Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.MouseOver.Border}"/>
    								<Setter Property="Fill" TargetName="optionMark" Value="{StaticResource OptionMark.MouseOver.Glyph}"/>
    								<Setter Property="Fill" TargetName="indeterminateMark" Value="{StaticResource OptionMark.MouseOver.Glyph}"/>
    							</Trigger>
    							<Trigger Property="IsEnabled" Value="false">
    								<Setter Property="Background" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.Disabled.Background}"/>
    								<Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.Disabled.Border}"/>
    								<Setter Property="Fill" TargetName="optionMark" Value="{StaticResource OptionMark.Disabled.Glyph}"/>
    								<Setter Property="Fill" TargetName="indeterminateMark" Value="{StaticResource OptionMark.Disabled.Glyph}"/>
    							</Trigger>
    							<Trigger Property="IsPressed" Value="true">
    								<Setter Property="Background" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.Pressed.Background}"/>
    								<Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="{StaticResource OptionMark.Pressed.Border}"/>
    								<Setter Property="Fill" TargetName="optionMark" Value="{StaticResource OptionMark.Pressed.Glyph}"/>
    								<Setter Property="Fill" TargetName="indeterminateMark" Value="{StaticResource OptionMark.Pressed.Glyph}"/>
    							</Trigger>
    							<Trigger Property="IsChecked" Value="true">
    								<Setter Property="Opacity" TargetName="optionMark" Value="1"/>
    								<Setter Property="Opacity" TargetName="indeterminateMark" Value="0"/>
    								<Setter Property="Background" TargetName="markGrid" Value="blue"/>
    								<Setter Property="Fill" TargetName="optionMark" Value="white"/>
    							</Trigger>
    							<Trigger Property="IsChecked" Value="{x:Null}">
    								<Setter Property="Opacity" TargetName="optionMark" Value="0"/>
    								<Setter Property="Opacity" TargetName="indeterminateMark" Value="1"/>
    							</Trigger>
    						</ControlTemplate.Triggers>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    	</Window.Resources>
        <StackPanel>
            <Grid Height="180">
            	<Grid.Background>
            		<ImageBrush ImageSource="bckpic.jpg"/>
            	</Grid.Background>
                <StackPanel Width="150" Height="30" HorizontalAlignment="Right" VerticalAlignment="Top">
                    <loc:RigthButton HorizontalAlignment="Right"></loc:RigthButton>
                </StackPanel>
            </Grid>
            <StackPanel Height="150">
                <StackPanel Orientation="Horizontal" >
                    <Border Height="80" Width="80" Margin="35,10,10,10" CornerRadius="5" BorderBrush="Gray" BorderThickness="1">
                        <Border.Background>
                            <ImageBrush ImageSource="touxiang1.jpg"/>
                        </Border.Background>
                    </Border>
                    <StackPanel Width="180" Height="89" Margin="10,10,0,0">
                        <Border BorderBrush="Gray" CornerRadius="5" BorderThickness="1">
                            <StackPanel Width="180" Height="60">
                                <TextBox Height="25" Width="180" Background="{x:Null}" BorderThickness="0,0,0,1" Margin="0,5,0,0" FontSize="14" Foreground="Gray">用户名</TextBox>
                                <TextBox Height="25" Width="180" Background="{x:Null}" BorderThickness="0" Margin="0,2,0,0" FontSize="14" Foreground="Gray">密码</TextBox>
                            </StackPanel>
                        </Border>
                       
                        <StackPanel Orientation="Horizontal" Height="15" Width="180" Margin="0,10,0,0">
                            <CheckBox Style="{DynamicResource CheckBoxStyle1}">记住密码</CheckBox>
                            <CheckBox Style="{DynamicResource CheckBoxStyle1}" Margin="42,0,0,0">自动登陆</CheckBox>
                        </StackPanel>
    
                    </StackPanel>
    
                    <StackPanel Height="60" Margin="15">
                        <TextBlock Height="30">
    						<Hyperlink NavigateUri="http://zc.qq.com">注册账号</Hyperlink>
    					</TextBlock>
                        <TextBlock Height="30">
    						<Hyperlink NavigateUri="http://aq.qq.com/">找回密码</Hyperlink>
    					</TextBlock>
                    </StackPanel>
    
                </StackPanel>
    
                <Border Height="30" Width="180" Margin="20,5,0,0" CornerRadius="5" BorderBrush="#FF0E95F1" BorderThickness="1">
                    <Button Height="30" FontWeight="Bold" Width="180" Content="登  陆" FontFamily="宋体" Foreground="White" Background="#FF0E95F1" BorderThickness="0" Style="{DynamicResource ButtonStyle1}"></Button>
                </Border>    
            </StackPanel>
        </StackPanel>
    </Window>
    


    posted on 2019-04-01 14:53 NET未来之路 阅读(...) 评论(...) 编辑 收藏

    转载于:https://www.cnblogs.com/lonelyxmas/p/10636401.html

    展开全文
  • WPF实例实例比较多)

    热门讨论 2017-11-08 10:06:37
    WPF实例实例比较多) (wpf窗体继承)RibbonStyle2.zip (赛车游戏)GrandPrix_SRC.zip CustomRulesMVVM.zip ...WPF界面下的会员登录.rar 基于插件式的开发框架源码.rar 漂亮的WPF界面框架(OSGi.NET插件)源码.rar
  • WPF大量的实例.rar

    2019-06-17 09:07:07
    treeview.zip WPF.MDI.rar WpfApplication1.zip WPF中UserControl如何访问它所属的Window的控件或事件.txt WPF之DataGrid.rar WPF动态添加行列DATAGRID.rar WPF界面下的会员登录.rar 基于插件式的开发框架源码.rar ...
  • Wpf实例-MVVM模式实现的登录窗体

    万次阅读 2015-12-30 23:21:28
    Wpf的一个实例程序,使用MVVM模式实现登录界面

    参考资料 kingmoon [MVVM专题] 又见经典入门实例

    1. 程序截图

    程序截图

    2.程序的结构图

    程序的结构图

    3.说明:
    如图2所示,Model中存放的是User类文件

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace WpfApp.Model
    {
       public class User
        {
           public string UserName { get; set; }
           public int UserId { get; set; }
           public string Password { get; set; }
        }
    }

    ViewModel

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Windows.Input;
    using WpfApp.Model;
    using WpfApp.Command;
    using System.Windows;
    
    
    namespace WpfApp.ViewModel
    {
        public class UserViewModel : INotifyPropertyChanged
        {
            #region 私有字段
            private string userName;
    
            private string userPassword;
    
            private ICommand loginCommand;
    
            private User user = new User(); 
            #endregion
            #region 属性
            public ICommand LoginCommand
            {
                get { return loginCommand; }
            }
            public string UserName
            {
                get
                {
                    return userName;
                }
                set
                {
                    this.userName = value;
                    if (this.PropertyChanged != null)
                    {
                        this.PropertyChanged(this, new PropertyChangedEventArgs("UserName"));
                    }
                }
            }
    
            public string UserPassword
            {
                get
                {
                    return userPassword;
                }
                set
                {
                    this.userPassword = value;
                    if (this.PropertyChanged != null)
                    {
                        this.PropertyChanged(this, new PropertyChangedEventArgs("UserPassword"));
                    }
                }
            } 
            #endregion
    
            public UserViewModel()
            {
                user.UserId = 1;
                user.UserName = "huangxi";
                user.Password = "123";
                loginCommand = new LoginCommand(this);
            }
    
            #region 公共方法
            public void QueryData()
            {
                if (!string.IsNullOrEmpty(this.UserName))
                {
                    if (this.UserName != user.UserName)
                    {
                        return;
                    }
                    if (this.UserPassword != user.Password)
                    {
                        return;
                    }
                    MessageBox.Show("登录成功");
                }
            } 
            #endregion
            #region INotifyPropertyChanged成员
            public event PropertyChangedEventHandler PropertyChanged;
            #endregion
        }
    }
    

    还有Command,存放的是Command,实现了ICommand接口

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Input;
    using WpfApp.ViewModel;
    
    namespace WpfApp.Command
    {
        public class LoginCommand:ICommand
        {
            private UserViewModel userViewModel;
            #region ICommand成员
            public bool CanExecute(object parameter)
            {
                return true;
            }
    
            public event EventHandler CanExecuteChanged;
    
            public void Execute(object parameter)
            {
                userViewModel.QueryData();
            } 
            #endregion
    
            public LoginCommand(UserViewModel userViewModel)
            {
                this.userViewModel = userViewModel;
            }
        }
    }
    

    最后是View层,

    <Window x:Class="WpfApp.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <Label Content="用户名" HorizontalAlignment="Left" Margin="73,80,0,0" VerticalAlignment="Top"/>
            <Label Content="密码" HorizontalAlignment="Left" Margin="73,138,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.798,-0.492"/>
            <Button Content="BtnLogin" HorizontalAlignment="Left" Margin="229,221,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
            <TextBox  x:Name ="txtUserName" HorizontalAlignment="Left" Height="23" Margin="203,80,0,0" TextWrapping="Wrap"  VerticalAlignment="Top" Width="120" Text="{Binding UserName,Mode=TwoWay}"/>
    
            <TextBox x:Name="txtPassword" HorizontalAlignment="Left" Height="23" Margin="203,141,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Text="{Binding UserPassword,Mode=TwoWay}"/>
    
        </Grid>
    </Window>
    

    这里有一个问题,因为默认的Password没法绑定,这里采用的TextBox代替,网络上有很多Password的帮助类,有兴趣的同学可以自行百度。

    界面层的后台代码

    using System.Windows;
    using WpfApp.ViewModel;
    
    namespace WpfApp
    {
        /// <summary>
        /// MainWindow.xaml 的交互逻辑
        /// </summary>
        public partial class MainWindow : Window
        {
            private UserViewModel userViewModel = null;
            public MainWindow()
            {
                InitializeComponent();
                userViewModel = new UserViewModel();
                this.DataContext = userViewModel;
            }
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
    
                if (this.userViewModel != null)
                {
                    this.userViewModel.UserName = this.txtUserName.Text;
                    this.userViewModel.UserPassword = this.txtPassword.Text;
                    this.userViewModel.LoginCommand.Execute(null);
                }
            }
        }
    }
    

    到这里就结束了。

    展开全文
  • 里面包含一些资源:...WPF界面下的会员登录.rar WPF动态添加行列DATAGRID.rar WpfApplication1.zip WPF.MDI.rar wpf-treeview.zip MVVM.rar WPF中UserControl如何访问它所属的Window的控件或事件.txt TabControl.zip
  • WPF登陆跳转

    2021-01-20 21:05:50
    登录界面的输入框显示水印的提示信息,输入值后水印提示消息消失,并且在登录页面的ViewModel中绑定界面中输入的密码的值,每个不同的菜单对应不同的页面跳转。 当设置一个页面跳转即要实现一个事件。 图下示例用的...

    根据项目的需求放置不同的控件,页面的跳转可以通过消息的订阅和发布的方式进行。
    登录界面的输入框显示水印的提示信息,输入值后水印提示消息消失,并且在登录页面的ViewModel中绑定界面中输入的密码的值,每个不同的菜单对应不同的页面跳转。
    当设置一个页面跳转即要实现一个事件。
    图下示例用的是点击事件。通过点击该按钮获取后台代码并执行
    在这里插入图片描述

    该实例是通过页面获取到用户提供的密码与账号进行与数据库中的数据是否匹配。
    匹配与否都会回馈用户相关的信息。
    在这里插入图片描述

    当信息不需要验证的时候 只需要获取页面命名通过ShowDialog实现跳转
    在这里插入图片描述

    展开全文
  • C#编程宝典(十年典藏版).pdf

    千次下载 热门讨论 2012-12-22 12:56:41
    第2篇为范例演练篇,主要包括基础应用相关、数据库开发相关、图形图像及多媒体应用、WPF图形化显示系统等相关的范例;第3篇为项目实战篇,主要包括明日快递单打印系统、QQ自动登录器、雷速网络下载专家、编程词典...
  • 通过详细讲解密码登录框和科学计算器这两个实例,使读者深入、熟练地掌握采用MATAB GUI进行工程项目设计的精髓。每个实例都有详细的构思和源程序,源程序包含详细的注释说明。通过本章的练习,读者可以独立完成复杂...
  • 1.7.3 使用Windows Presentation Foundation(WPF) 1.7.4 Windows控件 1.7.5 Windows服务 1.7.6 Windows Communication Foundation(WCF) 1.8 C#在.NET企业体系结构中的作用 1.9 小结 第2章 C#基础 2.1 引言 2.2 第一...
  • C#高级编程(第6版)

    2011-05-11 11:10:30
     1.7.3 使用Windows Presentation Foundation(WPF)  1.7.4 Windows控件  1.7.5 Windows服务  1.7.6 Windows Communication Foundation(WCF)  1.8 C#在.NET企业体系结构中的作用  1.9 小结  第2章 C#基础  ...
  •  1.7.3 使用Windows Presentation Foundation(WPF)  1.7.4 Windows控件  1.7.5 Windows服务  1.7.6 Windows Communication Foundation(WCF)  1.8 C#在.NET企业体系结构中的作用  1.9 小结  第2章 C#基础  ...
  • 1.7.3 使用Windows Presentation Foundation(WPF) 1.7.4 Windows控件 1.7.5 Windows服务 1.7.6 Windows Communication Foundation(WCF) 1.8 C#在.NET企业体系结构中的作用 1.9 小结 第2章 C#基础 2.1 引言 2.2 第一...
  • 4.6 实现个性化窗体界面 181 4.7 无标题窗体拖动的两种方法 183 4.8 让程序只启动一次——单实例运行 184 4.9 实现系统托盘和热键呼出 185 4.10 进程与多线程的区别 190 4.11 创建多线程应用程序 191 4.12 WinForm...
  • 1.7.2 使用WPF 1.7.3 windowsStore应用程序 1.7.4 Windows服务 1.7.5 WCF 1.7.6 Windows WF 1.8 C#在.NET企业体系结构中的作用 1.9 小结 第2章 核心C# 2.1 C#基础 2.2 第一个C#程序 2.2.1 代码 2.2.2 编译并运行...
  • 1.7.2 使用WPF 1.7.3 windowsStore应用程序 1.7.4 Windows服务 1.7.5 WCF 1.7.6 Windows WF 1.8 C#在.NET企业体系结构中的作用 1.9 小结 第2章 核心C# 2.1 C#基础 2.2 第一个C#程序 2.2.1 代码 2.2.2 编译并运行...
  • 1.7.2 使用WPF 1.7.3 windowsStore应用程序 1.7.4 Windows服务 1.7.5 WCF 1.7.6 Windows WF 1.8 C#在.NET企业体系结构中的作用 1.9 小结 第2章 核心C# 2.1 C#基础 2.2 第一个C#程序 2.2.1 代码 2.2.2 编译并运行...
  • asp.net知识库

    2015-06-18 08:45:45
    如何在DotNet 2的登录组件中检索用户的锁定状态及解锁? ASP.NET 2.0, 想说爱你不容易 SqlDataSource WEB控件:当DeleteCommandType= 遭遇 ASP.NET 2.0 只读 TextBox 回发后信息丢失的 bug asp.net2.0:扩展...
  • 微软 VB2010 源码包

    2013-05-22 02:21:18
    一个聊天应用程序的任何实例发送的消息可由其他所有实例接收 Predictor:演示 Active Server Methods (ASMX) 和 Windows Communication Foundation (WCF) 技术之间的差异 WindowsForms:演示一个服务,该服务实现...
  • Android高级编程--详细书签版

    热门讨论 2013-02-06 17:37:52
    本书所介绍的各个应用实例简明扼要且极具实用价值,它们覆盖了Android 1.0的所有基本功能和高级功能。  由于Android 1.0是一个正在兴起的全新手机操作系统,所以当前支持它的手机还不多。和任何其他产品早期的...

空空如也

空空如也

1
收藏数 20
精华内容 8
关键字:

wpf登录界面实例