1) The background code at the view layer is very concise and mainly used to create a view model. Of course, if you use some technology, you do not need code here. However, in my opinion, nothing should be done. If all the page control is placed on the view model layer, the view model layer will eventually become the background code of the view, the mvvm mode will be meaningless.
Using mentities;
Using riaservices. Web;
Using system. Threading;
Using system. Dynamic;
Using system. Windows. Data;
Using mappstructure. viewmodel;
Namespace mappstructure
{
Public partial class mainpage: usercontrol
{
Public dynamicdataviewmodel viewmodel
{
Get {
Return this. datacontext as dynamicdataviewmodel;
}
Set {
This. datacontext = value;
}
}
Public mainpage ()
{
Initializecomponent ();
// You can also build it in other ways. In simple applications, this file basically does not need to write code by itself.
This. viewmodel = new dynamicdataviewmodel ();
}
2) page binding.
<SDK: DataGrid X: Name = "customgrid" itemssource = "{binding Path = datatable. Rows}" grid. Row = "1" autogeneratecolumns = "false">
<SDK: DataGrid. Columns>
<SDK: datagridtextcolumn canuserreorder = "true" binding = "{binding Path = [employeeid]. value, mode = oneway} "canuserresize =" true "canusersort =" true "width =" Auto "/>
<SDK: datagridtextcolumn canuserreorder = "true" binding = "{binding Path = [employeename]. value, mode = oneway} "canuserresize =" true "canusersort =" true "width =" Auto "/>
<SDK: datagridtextcolumn canuserreorder = "true" binding = "{binding Path = [employeedesc]. value, mode = oneway} "canuserresize =" true "canusersort =" true "width =" Auto "/>
<SDK: datagridtextcolumn canuserreorder = "true" binding = "{binding Path = [employeeage]. value, mode = oneway} "canuserresize =" true "canusersort =" true "width =" Auto "/>
</SDK: DataGrid. Columns>
</SDK: DataGrid>
Note the above binding method and path syntax.
<Button content = "query" command = "{binding Path = commands [button1command]}" commandparameter = "{binding elementname = customgrid, Path = selecteditem}" grid. row = "2" Height = "23" horizontalalignment = "Left" margin = "344,160," name = "Search" verticalalignment = "center"
Width = "75"/>
In this example, the command processing mode can be automatically and dynamically bound with a slight improvement, which is much better than the way to define commands one by one and is conducive to centralized maintenance processing.
So far, this series has been completed. The above code is tested and actually runs. If your data volume is large, you need to modify the Web. config configuration of the server to increase the maximum number of serializable objects. You can search for many problems online. In addition, the message mechanism can also be used. This can be done using Microsoft's Lightweight Framework, but do not use it badly.
PS: I hope you will give more comments. If you have any better methods, I hope you can give us some advice.