Silverlight practice example 7 (and the use of set attributes)-client view layer (V)

Source: Internet
Author: User
Tags silverlight

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.