A preliminary study on the Silverlight framework-View

Source: Internet
Author: User

Viewmodel and riaservice are implemented in the previous sections. Next let's take a look at the binding of viewmodel and view, as shown below:

The code for productionview. XAML is as follows:

<Usercontrol X: class = "mvvm. Client. Views. productionview"
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: Vm = "CLR-namespace: mvvm. Client. viewmodels. viewmodels; Assembly = mvvm. Client. viewmodels"
MC: ignorable = "D"
D: designheight = "300" D: designwidth = "400" xmlns: Data = "CLR-namespace: system. Windows. controls; Assembly = system. Windows. Controls. Data">
<! -- Add productionviewmodel reference -->
<Usercontrol. Resources>
<VM: productionviewmodel X: Name = "productionviewmodel"/>
</Usercontrol. Resources>
<! -- Bind to grid through datacontext -->
<Grid X: Name = "layoutroot" datacontext = "{binding source = {staticresource productionviewmodel}" minheight = "100">
<! -- Add the gdatagrid and datapager controls -->
<Data: DataGrid autogeneratecolumns = "true" name = "datagrid1" minheight = "20" minwidth = "100" grid. Row = "4"/>
<Data: datapager grid. Row = "5" name = "datapager1"/>
</GRID>
</Usercontrol>

Here, the control is bound to the data source in its *. CS file, which makes it easier for us to perform related operations. The Code is as follows:

 

Public partial class productionview: usercontrol
{
Public productionview ()
{
Initializecomponent ();
Bindinggrid ();
}

Void bindinggrid ()
{
This. productionviewmodel = new viewmodels. viewmodels. productionviewmodel ();
Base. datacontext = This. productionviewmodel;
This. productionviewmodel. querycommand. Execute (null );

// Wrap the itemlist in a pagedcollectionview for paging functionality
Pagedcollectionview itemlistview = new pagedcollectionview (this. productionviewmodel. listproduction );
If (itemlistview! = NULL)
{
Datagrid1.itemssource = itemlistview;
Datapager1.source = itemlistview;
Datapager1.pagesize = 20;
Datapager1.datacontext = This. datapager1;
}
}
}

In this way, we can associate the view with the viewmodel.

Designing and developing Silverlight in mvvm mode truly achieves the goal of separating pages from logic. In the above example, our view can also be implemented using WPF.

 

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.