范文健康探索娱乐情感热点
投稿投诉
热点动态
科技财经
情感日志
励志美文
娱乐时尚
游戏搞笑
探索旅游
历史星座
健康养生
美丽育儿
范文作文
教案论文
国学影视

界面控件DevExpressWinFormsMVVM入门指南登录表单(下)

  从本文档中,您将了解如何向应用程序添加登录表单。在本节教程中着重讨论了如何实现此任务,这基本上是附加应用程序功能的一部分。
  DevExpress Universal Subscription官方最新版免费下载试用,历史版本下载,在线文档和帮助文件下载-慧都网
  4. 您还需要向主表单的ViewModel中添加一些代码。由于主表单使用自动生成的MyDbContextViewModel 类,因此不建议将自定义代码直接添加到其中 - 如果您需要再次调用Scaffolding Wizard,可以重新生成模型。相反,创建一个位于单独文件中的部分类。 请注意,您必须将类构造函数从其原始文件移动到这个分部类。
  C# //MyDbContextViewModel.partial.cs public partial class MyDbContextViewModel { LoginViewModel loginViewModel;  protected MyDbContextViewModel() : base(UnitOfWorkSource.GetUnitOfWorkFactory()) { loginViewModel = LoginViewModel.Create(); loginViewModel.SetParentViewModel(this); } protected IDialogService DialogService { get { return this.GetService(); } } protected IMessageBoxService MessageService { get { return this.GetService(); } }  public override void OnLoaded(MyDbContextModuleDescription module) { base.OnLoaded(module); Login(); }  public virtual AppState State { get; set; } // Shows the Login View public void Login() { OnLogin(DialogService.ShowDialog(MessageButton.OKCancel, "Please enter you credentials", "LoginView", loginViewModel)); } //Occurs whenever the end-user clicks a dialog button void OnLogin(MessageResult result) { if(result == MessageResult.Cancel) State = AppState.ExitQueued; else { if(loginViewModel.IsCurrentUserCredentialsValid) State = AppState.Autorized; else Login(); } } protected void OnStateChanged() { this.RaiseCanExecuteChanged(x => x.Logout()); if(State == AppState.Autorized) Messenger.Default.Send(loginViewModel.CurrentUser.Login); else Messenger.Default.Send(string.Empty); } }  public enum AppState { NotAutorized, Autorized, ExitQueued }
  VB.NET "MyDbContextViewModel.partial.vb Partial Public Class MyDbContextViewModel Private loginViewModel As LoginViewModel  Protected Sub New() MyBase.New(UnitOfWorkSource.GetUnitOfWorkFactory()) loginViewModel = LoginViewModel.Create() loginViewModel.SetParentViewModel(Me) End Sub Protected ReadOnly Property DialogService() As IDialogService Get Return Me.GetService(Of IDialogService)() End Get End Property Protected ReadOnly Property MessageService() As IMessageBoxService Get Return Me.GetService(Of IMessageBoxService)() End Get End Property  Public Overrides Sub OnLoaded(ByVal [module] As MyDbContextModuleDescription) MyBase.OnLoaded([module]) Login() End Sub  Public Overridable Property State() As AppState " Shows the Login View Public Sub Login() OnLogin(DialogService.ShowDialog(MessageButton.OKCancel, "Please enter you credentials", "LoginView", loginViewModel)) End Sub "Occurs whenever the end-user clicks a dialog button Private Sub OnLogin(ByVal result As MessageResult) If result Is MessageResult.Cancel Then State = AppState.ExitQueued Else If loginViewModel.IsCurrentUserCredentialsValid Then State = AppState.Autorized Else Login() End If End If End Sub Protected Sub OnStateChanged() Me.RaiseCanExecuteChanged(Sub(x) x.Logout()) If State = AppState.Autorized Then Messenger.Default.Send(Of String)(loginViewModel.CurrentUser.Login) Else Messenger.Default.Send(Of String)(String.Empty) End If End Sub End Class  Public Enum AppState NotAutorized Autorized ExitQueued End Enum
  下面列出了 LoginViewModel 和两个视图(MainView 和 LoginView)的代码。 当您的 ViewModel 准备就绪时,重新构建项目并将 MvvmContext 组件添加到登录表单中,使用其智能标签将 LoginViewModel 分配为此视图的相关视图模型。
  C# //LoginViewModel.cs public class LoginViewModel { public IEnumerable LookUpUsers { get { return CredentialsSource.GetUserNames(); } } public virtual User CurrentUser { get; set; } public bool IsCurrentUserCredentialsValid { get; private set; }  [DevExpress.Mvvm.DataAnnotations.Command(false)] public void Init() { this.CurrentUser = new User(); } public void Update() { IsCurrentUserCredentialsValid = CredentialsSource.Check(CurrentUser.Login, CurrentUser.Password); } public static LoginViewModel Create() { return ViewModelSource.Create(); } }  //MainView.cs public MainView() { InitializeComponent(); this.Opacity = 0; . . . }  void InitializeNavigation() { . . . var fluentAPI = mvvmContext1.OfType(); fluentAPI.SetTrigger(x => x.State, (state) => { if(state == AppState.Autorized) Opacity = 1; /*Show Main Form*/ if(state == AppState.ExitQueued) Close(); // exit the app; }); }  //LoginView.cs public partial class LoginView : DevExpress.XtraEditors.XtraUserControl { public LoginView() { InitializeComponent(); }  protected override void OnLoad(System.EventArgs e) { base.OnLoad(e); var fluentAPI = mvvmContext1.OfType(); fluentAPI.SetObjectDataSourceBinding(userBindingSource, x => x.CurrentUser, x => x.Update());  foreach(string item in mvvmContext1.GetViewModel().LookUpUsers) LoginTextEdit.Properties.Items.Add(item); fluentAPI.ViewModel.Init(); } }
  VB.NET "LoginViewModel.vb Public Class LoginViewModel Public ReadOnly Property LookUpUsers() As IEnumerable(Of String) Get Return CredentialsSource.GetUserNames() End Get End Property Public Overridable Property CurrentUser() As User Private privateIsCurrentUserCredentialsValid As Boolean Public Property IsCurrentUserCredentialsValid() As Boolean Get Return privateIsCurrentUserCredentialsValid End Get Private Set(ByVal value As Boolean) privateIsCurrentUserCredentialsValid = value End Set End Property   Public Sub Init() Me.CurrentUser = New User() End Sub Public Sub Update() IsCurrentUserCredentialsValid = CredentialsSource.Check(CurrentUser.Login, CurrentUser.Password) End Sub Public Shared Function Create() As LoginViewModel Return ViewModelSource.Create(Of LoginViewModel)() End Function End Class  "MainView.vb Public Sub New() InitializeComponent() Me.Opacity = 0 . . . End Sub  Private Sub InitializeNavigation() . . . Dim fluentAPI = mvvmContext1.OfType(Of MyDbContextViewModel)() fluentAPI.SetTrigger(Function(x) x.State, Sub(state) If state = AppState.Autorized Then Opacity = 1 End If If state = AppState.ExitQueued Then Close() End If End Sub) " exit the app; - Show Main Form End Sub  "LoginView.vb Partial Public Class LoginView Inherits DevExpress.XtraEditors.XtraUserControl  Public Sub New() InitializeComponent() End Sub  Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) MyBase.OnLoad(e) Dim fluentAPI = mvvmContext1.OfType(Of LoginViewModel)() fluentAPI.SetObjectDataSourceBinding(userBindingSource, Function(x) x.CurrentUser, Function(x) x.Update())  For Each item As String In mvvmContext1.GetViewModel(Of LoginViewModel)().LookUpUsers LoginTextEdit.Properties.Items.Add(item) Next item fluentAPI.ViewModel.Init() End Sub End Class
  此代码使用 OnLoaded 方法重载来显示使用已注册 DialogService 的对话框,为此Login方法调用服务的ShowDialog扩展方法,此方法将子 ViewModel 作为参数 - 将 LoginViewModel 类的新实例传递给它。创建这个实例很重要,不是使用 new 关键字,而是调用 ViewModelSource.Create 方法。或者,您可以调用 SetParentViewModel 方法为此实例设置父 ViewModel。
  当最终用户单击任何登录对话框的按钮时,此消息结果将传递给 OnLogin 方法,该方法会准确检查单击了哪个按钮。 如果最终用户单击 ‘Cancel’ 或关闭对话框,则应用程序将关闭。如果单击‘OK’按钮,应用程序将检查 IsCurrentUserCredentialsValid 属性,该属性会在调用 Update 方法时自动刷新其值。如果输入的凭据有效,将显示主表单,否则将重新显示登录表单,这是通过为 State 属性分配不同的值来完成的。 MainView 有一个触发器,用于监视 State 属性值的变化,并在它发生时做出相应的反应。
  5. 前面的步骤足以实现具有最少功能的登录表单。 但是,如果您的主视图分配了关闭确认操作,可能会遇到某些问题。 例如,如果您关闭登录表单,主表单(由于未输入有效凭据而变得透明)也将尝试自行关闭。 这将显示确认消息,如果您单击‘Cancel’按钮,表格将保留,但您将看不到它。 要克服此类问题,请删除表单关闭操作(如果有)并添加以下代码。
  C# //MainView.cs fluentAPI.WithEvent(this, "FormClosing") .EventToCommand(x => x.OnClosing(null), new Func((args) => args));  //MyDbContextViewModel.partial.cs public override void OnClosing(CancelEventArgs cancelEventArgs) { base.OnClosing(cancelEventArgs); if(!cancelEventArgs.Cancel) { if(State == AppState.Autorized && MessageService.ShowMessage("Do you really want to close the application?", "Confirm", MessageButton.YesNo) == MessageResult.No) cancelEventArgs.Cancel = true; } }
  VB.NET "MainView.vb fluentAPI.WithEvent(Of FormClosingEventArgs)(Me, "FormClosing").EventToCommand(Function(x) x.OnClosing(Nothing), New Func(Of CancelEventArgs, Object)(Function(args) args))  "MyDbContextViewModel.partial.vb public override void OnClosing(CancelEventArgs cancelEventArgs) MyBase.OnClosing(cancelEventArgs) If Not cancelEventArgs.Cancel Then If State = AppState.Autorized AndAlso MessageService.ShowMessage("Do you really want to close the application?", "Confirm", MessageButton.YesNo) = MessageResult.No Then cancelEventArgs.Cancel = True End If End If
  此代码检查当前的 State 属性值,仅在授权通过时显示确认消息。 如果最终用户尚未登录并决定关闭应用程序,则不会显示任何确认信息。 这就是为什么 State 属性不是布尔值,而是接受自定义 AppState 枚举器的值的原因。 可能存在三种应用状态: Authorized (已授权) - 用户凭据有效。 主表单是可见的,尝试关闭它应该会显示确认消息,最终用户可以单击 ‘No’ 来保持应用程序运行。 NotAuthorized  - 输入了用户凭据,但未通过验证。 主应用程序表单保持透明,登录表单重新显示。 ExitQueued  - 未输入用户凭据,登录表单已关闭,应用程序应在没有任何确认对话框的情况下终止。
  6. 您的登录表单现已准备就绪。可以通过为密码编辑器设置特定的 RepositoryItemTextEdit.PasswordChar 来装饰它,在主表单上反映登录用户的名称,并将按钮添加到主视图的网格控件中,以便您重新登录等,下面的代码说明了 怎么做。
  C# //LoginView.cs PasswordTextEdit.Properties.PasswordChar = "*";  //MyDbContextViewModel.partial.cs protected void OnStateChanged() { this.RaiseCanExecuteChanged(x => x.Logout()); if(State == AppState.Authorized) Messenger.Default.Send(loginViewModel.CurrentUser.Login); else Messenger.Default.Send(string.Empty); }  public void Logout() { State = AppState.ExitQueued; System.Diagnostics.Process.Start(System.Windows.Forms.Application.ExecutablePath); }  public bool CanLogout() { return State == AppState.Authorized; } //MainView.cs Messenger.Default.Register(this, OnUserNameMessage); fluentAPI.BindCommand(biLogout, x => x.Logout());  void OnUserNameMessage(string userName) { if(string.IsNullOrEmpty(userName)) this.Text = "Expenses Application"; else this.Text = "Expenses Application - (" + userName + ")"; }
  VB.NET "LoginView.vb PasswordTextEdit.Properties.PasswordChar = "*"c  "MyDbContextViewModel.partial.vb protected void OnStateChanged() Me.RaiseCanExecuteChanged(Sub(x) x.Logout()) If State = AppState.Authorized Then Messenger.Default.Send(Of String)(loginViewModel.CurrentUser.Login) Else Messenger.Default.Send(Of String)(String.Empty) End If  public void Logout() State = AppState.ExitQueued System.Diagnostics.Process.Start(System.Windows.Forms.Application.ExecutablePath)  public Boolean CanLogout() Return State = AppState.Authorized "MainView.vb Messenger.Default.Register(Of String)(Me, AddressOf OnUserNameMessage) fluentAPI.BindCommand(biLogout, Function(x) x.Logout())  void OnUserNameMessage(String userName) If String.IsNullOrEmpty(userName) Then Me.Text = "Expenses Application" Else Me.Text = "Expenses Application - (" & userName & ")" End If
  DevExpress WinForm
  DevExpress WinForm拥有180+组件和UI库,能为 Windows Forms 平台创建具有影响力的业务解决方案。DevExpress WinForms能完美构建流畅、美观且易于使用的应用程序,无论是Office风格的界面,还是分析处理大批量的业务数据,它都能轻松胜任!

实拍陕西三原张家窑民俗村有点凄美成熟黄杏没人吃落地上可惜在去陕西三原柏社村看地坑院的路上,看到一牌子上指示左转是张家窑民俗村,便决定去看一看。张家窑民俗村依山而建,很有特色,站在高处看挺美的,但整个景区却看不到游客,有一点凄美的感觉。走西安穿汉服的人越来越多让人联想京都和服梦回汉唐明天更辉煌西安古称长安,是世界四大古都之一,是中华文明和中华民族重要发祥地。汉唐盛世,万国来朝,汉民族文化从长安走向世界。岁月的洗礼,梦回汉唐,今天的人们怀念那个时期,强大的民族文化影响世界养牛大户自备三台机器收麦杆大部分农户不要钱也有人不给要还田以前,在很多地区麦子收完了,都一把火烧了麦秆既节省人力又能做肥料。近几年为了环保不允许烧麦秆,农户自己收麦秆不够功夫钱,很多人都利用机器粉碎直接还田。在陕西黄河边看到有人在地里收麦建于清代现还储存几千吨小麦的丰图义仓慈禧御封天下第一仓位于陕西省大荔县城东17公里处朝邑镇南寨子村的丰图义仓,是全国重点文物保护单位,慈禧太后曾御封此仓为天下第一仓。丰图义仓是始建于1882年(清光绪八年)的一座民办仓库,是中国所存无西安渭河一工地引崖沙燕筑巢可爱的生灵离我们那么近需要保护最近我经过渭河时,看到河滩上有一处土崖,崖壁上有许多小洞,无数小鸟在此驻足盘旋,远远望去场面很是壮观。于是我决定走下河滩,走近土崖,去仔细瞧瞧这些可爱的小家伙们。我走进河道,慢慢靠西安回民街父母和双胞胎女儿走散好心人帮忙母女拥抱瞬间暖心西安回民街上一个女孩嚎啕大哭,看上去45岁的样子,走几步停一停,感觉是和父母走散了。回民街上游客比较多,找起人来也比较麻烦。有好心人问女孩是不是找不到妈妈了,女孩也不说话只是一直哭古村偶遇一户人家墙上种满仙人掌老人讲即美观又能入药去探访古村,发现一户人家的院墙上种满了仙人掌,感觉挺新奇,也感叹仙人掌顽强的生命力。村里老人讲,墙上种仙人掌可以防盗,小偷也害怕仙人掌的浑身刺。仙人掌还好打理。看着黄土墙上密密的仙西安高温天气在钟楼广场看来打卡的小姐姐防晒各有高招2018年6月13日,西安最高气温39度,行走在太阳直射下,感觉身体被融化。钟鼓楼广场是外地游客到西安必游之地,整个广场在太阳直射下非常炙烤,在这里可以看到各地的游客防晒各有高招。西安渭河边两只黑翅长脚鹬在头顶盘旋不飞远看到幼鸟好像明白了现在西安渭河边的鸟越来越多了,但这些鸟还是很怕人,人靠近鸟会飞远。近几年,西安各条河边的黑翅长脚鹬也多了起来。黑翅长脚鹬是国家保护动物,繁殖期为57月。春季45月初迁来中国北方繁殖中望结构仿真算例教程(二)细长杆模态分析早前发布的关于中望结构仿真算例教程来到第二期,今天要进行一个细长杆的模态分析,话不多说,马上进入教程。1仿真介绍模态分析是研究结构动力特性一种方法,一般应用在工程振动领域。其中,模比特币会是下一个郁金香泡沫吗?比特币今天又冲上热搜了,这次是因为重挫15。41(截止2021年5月19日2317),与2021年最高峰的63044。1美元跌落至37069。2美元,可以说史诗级别的震荡。每次比特
流血上市,姚劲波手上这只天鹅能飞起来吗?继58同城私有化后,姚劲波在资本市场上又有大动作。7月3日,天鹅到家向纽交所递交IPO招股书,计划以JIA为证券代码在纽交所挂牌上市,计划发行5。17亿普通股,摩根大通瑞银集团和中荣耀与紫光展锐,能否接棒华为?接棒不是那么容易的事!自从华为与荣耀分开后,各界都比较关心荣耀的发展,而就在前不久赵明还参加了高通的某个会,从这里我们也得知,荣耀的供应链基本是完善了,剩下的就是火力全开地追赶,且长城新能源已落后行业,2025的目标,魏建军有点大跃进了去年还是命悬一线,今年就大跃进了。这多少让人觉得说话的人不太真诚。就在上个月底,长城汽车掌门人魏建军在长城汽车2025年战略发布会上豪言壮语道2025年,长城汽车计划实现全球年销量为传统车企转型新能源提供样本,比亚迪6月销量新能源占比超8成都知道未来汽车市场是新能源汽车的天下,不少传统车企也正在向新能源转型,但转型成功的又有多少?虽然很多传统车企都造出了新能源汽车,但在销量上无一不是惨不忍睹,燃油车依旧是其销量主力。耳梦播报美国律所计划向滴滴发起集体诉讼,理由是误导投资者要知道滴滴刚上市的时候一度暴涨,股价达到18美元,市值超过800亿美元,短短几天时间,蒸发了数百亿美元的市值。所以呢,就有一家律师事务所罗森律师事务所(RosenLawFirm)宣滴滴企业版等25款App被下架严重违法违规收集使用个人信息根据举报,经检测核实,滴滴企业版等25款App(列表附后)存在严重违法违规收集使用个人信息问题。国家互联网信息办公室依据中华人民共和国网络安全法相关规定,通知应用商店下架上述25款得感谢美国的照顾,让华为P50成为国产化最高的旗舰在手机市场,华为是一个绕不开的话题,OPPO高管刘波在接受媒体采访时承认,在国内高端市场只有两个品牌,一个是苹果,另一个就是华为。可见不管是消费群体还是手机企业,都给予了华为很高的将战略目标转化结果成效目标管理大数据前景广阔赛迪网讯伴随着数字时代的到来,大数据的关注度也越来越高,回首过去十年,我国的数据量不仅增长速度迅速,大数据技术和产业大数据应用也越来越成熟,以大数据作为支撑推动产业数字化转型已是热360借条被下架,原因是什么?360借条被要求下架的消息公布后引起了不少朋友的关注。360借条的相关负责人并没有对此予以否认,但也没有透露具体下架的原因。因此,只能根据此前的消息做一些推测。1。利息太高,所以下别了学位房,电区房要来了!至少选择蔚来这个品牌,出行就不用担心了。今年的NIOPowerDay上,蔚来总裁秦力洪抛出了这样一番豪言壮语。确实,蔚来有底气去说这么一番话。时至今日,NIOPower体系的便利性新基建的基本内涵根据中央的提法和发展的实践,我们认为,新基建以5G人工智能工业互联网,物联网,数据中心云计算固定宽带,重大科技设施为重点,致力于打造数字化智能化的新型基础设施,运用数字化智能化技术