国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

WPF實(shí)戰(zhàn)學(xué)習(xí)筆記29-登錄數(shù)據(jù)綁定,編寫(xiě)登錄服務(wù)

這篇具有很好參考價(jià)值的文章主要介紹了WPF實(shí)戰(zhàn)學(xué)習(xí)筆記29-登錄數(shù)據(jù)綁定,編寫(xiě)登錄服務(wù)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

添加登錄綁定字段、命令、方法

修改對(duì)象:Mytodo.ViewModels.ViewModels

using Mytodo.Service;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Shapes;

namespace Mytodo.ViewModels
{
    public class LoginViewModel : BindableBase, IDialogAware
    {


        #region 定義命令
        /// <summary>
        /// 執(zhí)行登錄|推出等相關(guān)命令
        /// </summary>
        public DelegateCommand<string> ExecuteCommand { get; set; }
        #endregion

        #region 定義屬性

        public string Password
        {
            get { return password; }
            set { password = value; }
        }

        public string Account
        {
            get { return account; }
            set { account = value; }
        }

        #endregion

        #region 定義重要字段

        #endregion

        #region 定義普通字段
        private string password;
        private string account;
        private readonly ILoginService loginService;
        private readonly IEventAggregator aggregator;
        #endregion

        #region 命令方法
        /// <summary>
        /// ExecuteCommand對(duì)應(yīng)的方法
        /// </summary>
        /// <param name="obj"></param>
        private void Execute(string obj)
        {
            switch (obj)
            {
                case "Login": Login(); break;
                case "LoginOut": LoginOut(); break;
                //case "Resgiter": Resgiter(); break;
                //case "ResgiterPage": SelectIndex = 1; break;
                //case "Return": SelectIndex = 0; break;
            }
        }

        private void LoginOut()
        {
            //if (string.IsNullOrWhiteSpace(UserName) ||
            //   string.IsNullOrWhiteSpace(PassWord))
            //{
            //    return;
            //}

            //var loginResult = await LoginService.Login(new Shared.Dtos.UserDto()
            //{
            //    Account = UserName,
            //    PassWord = PassWord
            //});

            //if (loginResult != null && loginResult.Status)
            //{
            //    RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
            //}
            //else
            //{
            //    //登錄失敗提示...
            //    aggregator.SendMessage(loginResult.Message, "Login");
            //}
        }

        private void Login()
        {
            //throw new NotImplementedException();
        }

        #endregion

        #region 啟動(dòng)項(xiàng)

        #endregion

        #region 繼承
        public string Title { get; set; } = "Todo";


        public event Action<IDialogResult> RequestClose;

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
            LoginOut();
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {

        }
        #endregion

        public LoginViewModel(ILoginService loginService, IEventAggregator aggregator)
        {
            ExecuteCommand = new DelegateCommand<string> (Execute);
            this.loginService = loginService;
            this.aggregator = aggregator;
        }

  
    }
}

添加密碼依賴(lài)對(duì)象行為

添加文件:Mytodo.Extensions.PassWordExtensions

using Microsoft.Xaml.Behaviors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace Mytodo.Extensions
{
    public class PassWordExtensions
    {
        public static string GetPassWord(DependencyObject obj)
        {
            return (string)obj.GetValue(PassWordProperty);
        }

        public static void SetPassWord(DependencyObject obj, string value)
        {
            obj.SetValue(PassWordProperty, value);
        }

        // Using a DependencyProperty as the backing store for PassWord.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty PassWordProperty =
            DependencyProperty.RegisterAttached("PassWord", typeof(string), typeof(PassWordExtensions), new FrameworkPropertyMetadata(string.Empty, OnPassWordPropertyChanged));

        private static void OnPassWordPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var passWord = d as PasswordBox;
            string password = (string)e.NewValue;

            if (passWord != null && passWord.Password != password)
                passWord.Password = password;
        }

    }

    public class PasswordBehavior : Behavior<PasswordBox>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.PasswordChanged += AssociatedObject_PasswordChanged;
        }

        private void AssociatedObject_PasswordChanged(object sender, RoutedEventArgs e)
        {
            PasswordBox passwordBox = sender as PasswordBox;
            string password = PassWordExtensions.GetPassWord(passwordBox);

            if (passwordBox != null && passwordBox.Password != password)
                PassWordExtensions.SetPassWord(passwordBox, passwordBox.Password);
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
            AssociatedObject.PasswordChanged -= AssociatedObject_PasswordChanged;
        }
    }
}

### 登錄UI添加密碼行為

修改文件:Mytodo.Views.LoginView.xmal

  1. 添加命名空間,略
  2. 修改passbox。
<PasswordBox
             Margin="0,10"
             md:HintAssist.Hint="請(qǐng)輸入密碼"
             pass:PassWordExtensions.PassWord="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
             DockPanel.Dock="Top">
    <i:Interaction.Behaviors>
        <pass:PasswordBehavior />
    </i:Interaction.Behaviors>
</PasswordBox>

添加加密方法,并使用

添加文件:MyToDo.Share.StringExtensions.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace MyToDo.Share
{
    public static class StringExtensions
    {
        public static string GetMD5(this string data)
        {
            if (string.IsNullOrWhiteSpace(data))
                throw new ArgumentNullException(nameof(data));

            var hash = MD5.Create().ComputeHash(Encoding.Default.GetBytes(data));

            return Convert.ToBase64String(hash);//將加密后的字節(jié)數(shù)組轉(zhuǎn)換為加密字符串
        }
    }
}

客戶(hù)端添加登錄和注冊(cè)接口

添加文件:Mytodo.Service.cs

using MyToDo.Share.Models;
using MyToDo.Share;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mytodo.Service
{
    public interface ILoginService
    {
        Task<ApiResponse> Login(UserDto user);

        Task<ApiResponse> Resgiter(UserDto user);
    }
}

添加文件:Mytodo.Service.LoginService

using MyToDo.Share;
using MyToDo.Share.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mytodo.Service
{
    public class LoginService : ILoginService
    {
        private readonly HttpRestClient client;
        private readonly string serviceName = "Login";

        public LoginService(HttpRestClient client)
        {
            this.client = client;
        }

        public async Task<ApiResponse> Login(UserDto user)
        {
            BaseRequest request = new BaseRequest();
            request.Method = RestSharp.Method.POST;
            request.Route = $"api/{serviceName}/Login";
            request.Parameter = user;
            return await client.ExecuteAsync(request);
        }

        public async Task<ApiResponse> Resgiter(UserDto user)
        {
            BaseRequest request = new BaseRequest();
            request.Method = RestSharp.Method.POST;
            request.Route = $"api/{serviceName}/Resgiter";
            request.Parameter = user;
            return await client.ExecuteAsync(request);
        }
    }
}

注冊(cè)接口和服務(wù)

Mytodo.app.xaml.cs 添加內(nèi)容containerRegistry.Register<ILoginService, LoginService>();文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-617651.html

到了這里,關(guān)于WPF實(shí)戰(zhàn)學(xué)習(xí)筆記29-登錄數(shù)據(jù)綁定,編寫(xiě)登錄服務(wù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀(guān)點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記21-自定義首頁(yè)添加對(duì)話(huà)服務(wù)

    定義接口與實(shí)現(xiàn) 添加自定義添加對(duì)話(huà)框接口 添加文件:Mytodo.Dialog.IDialogHostAware.cs 添加自定義添加對(duì)話(huà)框顯示接口 注意dialogHostName應(yīng)與view中dialoghost 的Identifier屬性一致 實(shí)現(xiàn)IDialogHostService接口 添加文件:Mytodo.Dialog.DialogHostService.cs DialogHostService實(shí)現(xiàn)了自定義的IDialogHostService接口

    2024年02月15日
    瀏覽(16)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記16-數(shù)據(jù)加載

    新建Update事件,增加Prism事件列表 新建文件Mytodo/Common/Events/UpdateLoadingEvent.cs 新建含加載窗體基類(lèi) 新建文件Mytodo/ViewModels/NavigationViewModel.cs 建立數(shù)據(jù)加載窗體擴(kuò)展方法 新建文件Mytodo/Extensions/DialogExtension.cs 主窗口命名 修改文件Mytodo/Extensions/DialogExtension.cs 主窗口訂閱消息 修改文

    2024年02月15日
    瀏覽(22)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記08-創(chuàng)建數(shù)據(jù)庫(kù)

    創(chuàng)建文件夾 ./Context 創(chuàng)建文件 ./Context/BaseEnity.cs ./Context/Memo.cs ./Context/MyTodoContext.cs ./Context/Todo.cs ./Context/User.cs 創(chuàng)建數(shù)據(jù)對(duì)象 ./Context/BaseEnity.cs ./Context/Memo.cs ./Context/MyTodoContext.cs 創(chuàng)建數(shù)據(jù)庫(kù)DbSet ./Context/Todo.cs ./Context/User.cs 添加nuget包 Microsoft.EntityFrameworkCore.Design Shared design-time co

    2024年02月16日
    瀏覽(46)
  • WPF 入門(mén)筆記 - 04 - 數(shù)據(jù)綁定

    WPF 入門(mén)筆記 - 04 - 數(shù)據(jù)綁定

    慢慢來(lái),誰(shuí)還沒(méi)有一個(gè)努力的過(guò)程。 --網(wǎng)易云音樂(lè) 數(shù)據(jù)綁定概述 (WPF .NET) 什么是數(shù)據(jù)綁定? 數(shù)據(jù)綁定(Data Binding)是 WPF 一種強(qiáng)大的機(jī)制,用于在應(yīng)用程序的各個(gè)部分之間建立數(shù)據(jù)的雙向關(guān)聯(lián)。它允許你將數(shù)據(jù)從一個(gè)源(例如對(duì)象、集合、數(shù)據(jù)庫(kù)等)綁定到目標(biāo)控件的屬性,

    2024年02月09日
    瀏覽(22)
  • WPF 入門(mén)筆記 - 04 - 數(shù)據(jù)綁定 - 補(bǔ)充內(nèi)容:資源基礎(chǔ)

    WPF 入門(mén)筆記 - 04 - 數(shù)據(jù)綁定 - 補(bǔ)充內(nèi)容:資源基礎(chǔ)

    宇宙很大,生活更大,也許以后還有緣相見(jiàn)。 --三體 ?? ?? 該篇作為[WPF 入門(mén)筆記 - 04 - 數(shù)據(jù)綁定] - Additional Content 章節(jié)的補(bǔ)充內(nèi)容 XAML 資源概述 (WPF .NET) WPF中的每一個(gè)元素都有一個(gè) Resources 屬性,該屬性存儲(chǔ)了一個(gè)資源字典集合。一般來(lái)說(shuō),可以把WPF的資源按照不同的性質(zhì)分

    2024年02月11日
    瀏覽(23)
  • WPF 零基礎(chǔ)入門(mén)筆記(3):數(shù)據(jù)綁定詳解(更新中)

    WPF 零基礎(chǔ)入門(mén)筆記(3):數(shù)據(jù)綁定詳解(更新中)

    WPF基礎(chǔ)知識(shí)博客專(zhuān)欄 WPF微軟文檔 WPF控件文檔 B站對(duì)應(yīng)WPF數(shù)據(jù)綁定視頻教程 我們?cè)谥暗奈恼轮校敿?xì)解釋了數(shù)據(jù)模版和控件模板。簡(jiǎn)單來(lái)說(shuō)數(shù)據(jù)模板和控件模板就是為了解決代碼重復(fù)的問(wèn)題。我們可以回顧一下之前的所有內(nèi)容。 為了不寫(xiě)重復(fù)的樣式,WPF提供了樣式設(shè)置 為了

    2024年02月11日
    瀏覽(54)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記25-首頁(yè)匯總

    注意:本實(shí)現(xiàn)與視頻不一致。本實(shí)現(xiàn)中單獨(dú)做了匯總接口,而視頻中則合并到國(guó)todo接口當(dāng)中了。 添加匯總webapi接口 添加匯總數(shù)據(jù)客戶(hù)端接口 總數(shù)據(jù)客戶(hù)端接口對(duì)接3 首頁(yè)數(shù)據(jù)模型 添加數(shù)據(jù)匯總字段類(lèi) 新建文件MyToDo.Share.Models.SummaryDto 添加匯總webapi接口 添加匯總接口 添加文

    2024年02月15日
    瀏覽(19)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記26-首頁(yè)導(dǎo)航

    修改UI,添加單擊行為,并綁定導(dǎo)航命令 修改文件:Mytodo.Views.IndexView.xaml ,在導(dǎo)航梯形添加內(nèi)容 添加導(dǎo)航命令,并初始化 修改文件:indexviewmodel.cs 添加導(dǎo)航區(qū)域變量,并初始化 修改文件:indexviewmodel.cs 添加導(dǎo)航方法 TaskBars添加對(duì)應(yīng)的導(dǎo)航區(qū)域 修改OnNavigate方法 當(dāng)為“已完成

    2024年02月15日
    瀏覽(43)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記27-全局通知

    新建消息事件 添加文件:Mytodo.Common.Events.MessageModel.cs 注冊(cè)、發(fā)送提示消息 UI增加Snackbar 修改文件:Mytodo.Views.MainView.xaml 注冊(cè)消息 修改文件:Mytodo.Views.MainViewcs 構(gòu)造函數(shù)添加 要注意的是,我們要發(fā)送的是文本,所以,this.skbar.MessageQueue.Enqueue函數(shù)內(nèi)發(fā)送的是文本。 在需要的地

    2024年02月15日
    瀏覽(17)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記04-菜單導(dǎo)航

    添加文件與文件夾 添加文件夾 ? ./Extensions 添加文件 類(lèi)型:用戶(hù)控件 ./Views/IndexView.xaml ./Views/MemoView.xaml ./Views/TodoView.xaml ./Views/SettingsView.xaml ./ViewModels/IndexViewModel.cs ./ViewModels/IndexViewModel.cs ./ViewModels/IndexViewModel.cs ./ViewModels/IndexViewModel.cs ./Extensions/PrismManager.cs 建立View與Vie

    2024年02月16日
    瀏覽(18)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包