惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
Attack and Defense Labs
Attack and Defense Labs
V2EX - 技术
V2EX - 技术
O
OpenAI News
S
Secure Thoughts
H
Heimdal Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Schneier on Security
Schneier on Security
H
Hacker News: Front Page
S
Security Affairs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
The Register - Security
The Register - Security
GbyAI
GbyAI
Cloudbric
Cloudbric
MongoDB | Blog
MongoDB | Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
Forbes - Security
Forbes - Security
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
The Cloudflare Blog
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
Webroot Blog
Webroot Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
T
Tor Project blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
V
V2EX
T
Tailwind CSS Blog
SecWiki News
SecWiki News
NISL@THU
NISL@THU
C
Check Point Blog

博客园 - yo

Silverlight 缺陷 - yo - 博客园 SilverLight Controls WF 4.0 中 Persistence 异常 - yo SilverLight框架初探-RiaService SilverLight框架初探-ViewModel SilverLight框架初探 与客户“调情” AG_E_PARSER_BAD_PROPERTY_VALUE 定义属于自己的Routing 数据契约的序列化 WCF客户端配置问题 关闭EXCEL进程 母版页中控件ID获取 - yo - 博客园 Reportviewer - Error: ASP.NET session has expired - yo SQL CLR C# DLL动态调用 Sharepoint List faults - yo 出错页面webpar的t删除 quickpart
SilverLight框架初探-View - yo - 博客园
yo · 2010-03-17 · via 博客园 - yo

前面分别实现了ViewModel与Riaservice,接下来让我们看看如果实现与View的绑定,如下:

ProductionView.xaml的代码如下:

<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">
    <!--添加ProductionViewModel引用-->
    <UserControl.Resources>
        <vm:ProductionViewModel x:Name="productionViewModel"/>
    </UserControl.Resources>
    <!--通过DataContext与Grid绑定-->
    <Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource productionViewModel}}" MinHeight="100">
        <!--添加GdataGrid与DataPager控件-->
        <data:DataGrid AutoGenerateColumns="True" Name="dataGrid1" MinHeight="20" MinWidth="100" Grid.Row="4" />
        <data:DataPager Grid.Row="5" Name="dataPager1" />
    </Grid>
</UserControl>

在这里,控件与数据源的绑定放在了其*.cs文件中,这样更方便于我们进行相关操作,代码如下:

 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;
            }
        }
    }

这样,我们就能够将View与ViewModel关联起来。

以MVVM这么模式来设计开发Silverlight,真正意义上达到了我们要实现页面与逻辑分离的目的。上面例子中,我们的View也可以用WPF来实现。