当前位置: 首页 > news >正文

php mysql网站后台源码公司建立网站的步骤

php mysql网站后台源码,公司建立网站的步骤,深圳航空人工服务电话,南通网站设计公司最近学习了一下MvvmLight,觉得有些功能还是挺有特色的,所以记录一下 首先新建也给WPF程序 然后在Nuget里面安装MvvmLightLib 包,安装上面那个也可以,但是安装上面那个会自动在代码里面添加一些MvvmLight的demo ,安装M…

最近学习了一下MvvmLight,觉得有些功能还是挺有特色的,所以记录一下

首先新建也给WPF程序

然后在Nuget里面安装MvvmLightLib 包,安装上面那个也可以,但是安装上面那个会自动在代码里面添加一些MvvmLight的demo ,安装MvvmLightLib比较纯净

安装完成后,在App.cs 里面重写一下OnStartup方法,让程序启动的时候初始一下IOC容器和DispatcherHelper。(其实这两步也可以放在其他地方,比如放在构造函数里面或者其他地方也是可以的,没有特殊要求)

 MvvmLight的依赖属性

新建一个 MainViewModel 类 

让实体类继承ViewModelBase类,然后在属性的set访问器里面加上RaisePropertyChanged();就实现了MVVM,这比WPF原生的MVVM简单很多

MvvmLight的命令绑定

然后在界面上绑定命令:

 <Button Content="把名字修改成张三" Command="{Binding BtnCommand}" CommandParameter="张三"></Button>

这个是带参数的命令,如果不需要带参数,那么直接把参数删掉就行

MvvmLight的messenger

这个是MvvmLight的最有亮点的功能了

Messenger.Default.Send("aaaa", "myToken");

第一个参数是发送消息的内容,第二个参数是token的名称,所有此toten的注册者都能收到消息

按钮点击发送后,构造函数中的两个注册者都能收到消息。注册者可以在Model中,或者在其他的地方都能收到,这比使用委托更简单。

MvvmLight跨线程访问控件

DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                });

 这个方法可以跨线程访问控件,在实体类中不能用invoke的时候,就可以用这种方法

以上就是MvvmLight最实用的功能,其他花哨的功能我感觉用处不大

以下是完整代码:

app.cs

using CommonServiceLocator;
using GalaSoft.MvvmLight.Ioc;
using GalaSoft.MvvmLight.Threading;
using MvvmLightDemo.ViewModels;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;namespace MvvmLightDemo
{/// <summary>/// App.xaml 的交互逻辑/// </summary>public partial class App : Application{protected override void OnStartup(StartupEventArgs e){#region 注册MvvmLight的IOCServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);SimpleIoc.Default.Register<MainViewModel>();#endregionDispatcherHelper.Initialize();      //用于判断修改属性的时候是否处于UI线程,首先初始化一下base.OnStartup(e);}}
}

 MainWindow

<Window x:Class="MvvmLightDemo.MainWindow"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:MvvmLightDemo"mc:Ignorable="d"Title="MainWindow" Height="350" Width="525"><Grid><StackPanel><TextBlock Text="{Binding Name}"></TextBlock><Button Content="把名字修改成张三" Command="{Binding BtnCommand}" CommandParameter="张三"></Button><Button Click="Button_Click" Content="发送消息"></Button><Button Click="Button_Click_1"  Content="使用子线程修改数据"></Button><ItemsControl ItemsSource="{Binding NameList}"></ItemsControl></StackPanel></Grid>
</Window>
using CommonServiceLocator;
using GalaSoft.MvvmLight.Messaging;
using GalaSoft.MvvmLight.Threading;
using MvvmLightDemo.ViewModels;
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 MvvmLightDemo
{/// <summary>/// MainWindow.xaml 的交互逻辑/// </summary>public partial class MainWindow : Window{public MainWindow(){InitializeComponent();var model = ServiceLocator.Current.GetInstance<MainViewModel>();this.DataContext = model;Messenger.Default.Register<string>(this, "myToken", (str) =>{Console.WriteLine(str);});Messenger.Default.Register<string>(this, "myToken", (str) =>{Console.WriteLine(str);});}private void Button_Click(object sender, RoutedEventArgs e){Messenger.Default.Send("aaaa", "myToken");}private void Button_Click_1(object sender, RoutedEventArgs e){Task.Run(() => {DispatcherHelper.CheckBeginInvokeOnUI(() =>{var model = ServiceLocator.Current.GetInstance<MainViewModel>();        //在IOC容器中获取单例model.NameList.Add("aaa");model.NameList.Add("bbb");model.Name = "34242";});});}}
}

MainViewModel

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;namespace MvvmLightDemo.ViewModels
{public class MainViewModel : ViewModelBase{#region MvvmLight的依赖属性private string name = "默认名字";public string Name{get { return name; }set{name = value;RaisePropertyChanged();     //加上了这行代码,属性就具有了通知功能}}#endregionprivate ObservableCollection<string> nameList = new ObservableCollection<string>() { "默认1", "默认2" };public ObservableCollection<string> NameList{get { return nameList; }set{nameList = value;}}#region MvvmLight的命令绑定private ICommand btnCommand;public ICommand BtnCommand{get{if (btnCommand == null){btnCommand = new RelayCommand<string>(DoCommand);}return btnCommand;}set { btnCommand = value; }}private void DoCommand(string str){Name = str;Console.WriteLine(str);}#endregion}
}

http://www.hkea.cn/news/725708/

相关文章:

  • 网站建设 青海网站建设找哪家好
  • win7 网站配置优化方案官网电子版
  • 广州seo优化公司排名浙江seo博客
  • 全网推广的方式有哪些抖音seo推荐算法
  • 网站开发开源架构抖音营销软件
  • 自己做的网站能放到网上么青岛seo经理
  • 营业推广策划方案邵阳网站seo
  • 手机网站横向切换kol合作推广
  • 专门做超市海报的网站宁波seo咨询
  • 仿网站上的焦点图在线看seo网站
  • 做网站的业务员艾滋病阻断药有哪些
  • web集团网站建设广告投放平台有哪些
  • 大连做网站建设广告资源对接平台
  • 做网站怎么写工作日志泉州网站seo公司
  • wordpress外链站内打开搜索引擎是什么意思啊
  • 做论坛网站需要什么备案新站seo优化快速上排名
  • 动漫网站html百度网盘搜索
  • 怎么看一个网站什么语言做的宝鸡seo培训
  • 数据库网站建设公司他达拉非片
  • 英文商城网站建设搜索引擎营销的特点
  • 易优建站系统图片百度搜索
  • 网站开发不用框架web网站设计
  • 技能网站建设项目需求武汉网络推广外包公司
  • 安卓市场下载手机版优化网站排名技巧
  • 建设网站平台哪个好互联网营销外包推广
  • 工商注册企业名称查询广东seo网站推广代运营
  • 中纪委网站两学一做征文资源平台
  • java高端网站建设现在广告行业好做吗
  • wordpress 制作下载优化关键词怎么做
  • 宁波网站建设哪个公司好百度爱采购推广怎么入驻