silverlight知识积累

silverlight+prism进行程序开发,采用MVVM的模式。

1. import view

1)import方法

[Import]
public DPlanCheckRecordView dPlanCheckRecordView { get; set; }
2)导航
IRegionManager
Uri uri = new Uri("FilldayplanMainView", UriKind.Relative);
_regionManager.RequestNavigate(RegionNames.CMainRegion, uri);
3)IServiceLocator
public FilldayplanMainView filldayplanMainView { get; set; }
filldayplanMainView = _serviceLocator.GetInstance(typeof(FilldayplanMainView),
   "FilldayplanMainView") as FilldayplanMainView;
2. 导航(新建或编辑)打开页面
Query页面点击编辑按钮:
public void editDPlan()
        {
            DayPlanItem item = DayPlanItems.CurrentItem as DayPlanItem;
            if (item != null)
            {
                filldayplanMainView = _serviceLocator.GetInstance(typeof(FilldayplanMainView),
                     "FilldayplanMainView") as FilldayplanMainView;
                UriQuery query = new UriQuery();
                query.Add("planOperation", FillDayPlan.Models.DayPlanOperation.Edit.ToString());
                query.Add("DayPlanId", item.MdplanId);
                Uri uri = new Uri("FilldayplanMainView"+query.ToString(), UriKind.Relative);
                _regionManager.RequestNavigate(RegionNames.CMainRegion, uri);
            }
        }
要导航到的页面的ViewModel实现INavigationAware接口
[Export]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class FilldayplanMainViewModel : NotificationObject, INavigationAware
    {
       ...
public void OnNavigatedTo(NavigationContext navigationContext)
        {
            UriQuery query = navigationContext.Parameters;
            if (query != null && query["planOperation"] != null)
            {
                _planOperation = (DayPlanOperation)Enum.Parse(typeof(DayPlanOperation),
                      query["planOperation"], true);
                _queryItem.MdplanId = query["DayPlanId"];
                if (_planOperation == DayPlanOperation.Edit)
                {
                    //根据查询条件查询dayplan
                    _model.SelectDayplan(_queryItem.MdplanId);
                }
            }
        }
    }

//参考
1. http://www.silverlightchina.net/html/tips/2011/0210/5257.html
This entry was posted in Computer, Silverlight. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s