In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
1. What is MVVM?
MVVM is the abbreviation of Model, View and ViewModel. The introduction of this mode is to use ViewModel to reduce the coupling between View and Model, that is to say, to reduce the coupling between View and Model. It can also be said to reduce the coupling of interface and logic. Ideally, the interface and logic are completely separated. When changing the interface unilaterally, there is no need to change the logic code, and the same logic code does not need to change the interface. The same ViewModel can be displayed using a completely unused View, and the same View can use different ViewModel to provide different operations.
two。 Project catalog
From the figure above, we can see that there are several types of files that handle transactions: View,ViewModel,Command,Property,Model, these types of pictures.
The bottom ViewModelBase.cs is Property, which corresponds to the transaction that handles the change that triggers property discovery.
3. Code analysis:
A): entry App.xaml
Private void Application_Startup (object sender, StartupEventArgs e) {/ / create a ViewModel; MainViewModel mode = new MainViewModel (); / / initialize ViewModel content mode.ItemDatas = new ObservableCollection (); mode.ItemDatas.Add (new ItemData {Title = "TST", Content = "sss"}) Mode.ItemDatas.Add (new ItemData {Title = "2TST", Content = "2sss"}); / / initialize View; MainWindow main = new MVVMGridDemo.MainWindow (); / / bind ViewModel to View main.DataContext = mode; / / display window main.Show ();}
B): MainWindow window ViewModel
View code
Viewmodel code
Public class MainViewModel: the value where Name is Texxt in ViewModelBase {private ObservableCollection _ itemdatas;//view implements private string _ texxt; public string TexxT {get {return this._texxt;} set {this._texxt = value; OnPropertyChanged ("TexxT") here. Data binding with itemsourse as ItemData in view Public ObservableCollection ItemDatas {get {return _ itemdatas;} set {this._itemdatas = value; OnPropertyChanged ("ItemDatas") }} / / modify button click event public ICommand ButtonClick {get {return new ActionCommand (p = > BClick (p));}} private void BClick (object obj) {DataGrid box = (DataGrid) obj; ItemDatas [0] .title = TexxT / / Refresh dataGrid box.Items.Refresh ();}}
Full source code: https://github.com/servucn/MVVMGridDemo
Address: http://www.ucasp.net/wpfresources/mvvmgriddemo.shtml
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.