开发者

Silverlight MVVM conversion from WPF

I was reading this article - http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

And I came across this piece of code in the WPF Demo application that came with the article.

This template applies a CustomerView to an instance of the CustomerViewModel class shown in the main window.

<DataTemplate DataType="{x:Type vm:CustomerViewModel}">  
    <vw:CustomerView />  
</DataTemplate>

I substituted the angle brackets for square brackets - not sure how to post them.

The code is in the MainWindowResourses.xaml and the code starts on line 19.

Anyone know how I can do this in Silverlight ?? We don't have t开发者_C百科he DataType and I need to be able to tell the app that this View is associated with this ViewModel - so I can create a tab control with different view like the demo app.

Cheers,

EC


This is an example of WPF implicit styling, where a style is applied to all the controls in the project. This is not supported in Silverlight.

To get around this you need to instead place your view controls in the markup and set their DataContext to the viewmodel.

<Window.Resources>
    <vm:CustomerViewModel x:Key="theViewModel">  
<Window.Resources>

<vw:CustomerView DataContext={StaticResource theViewModel}/>  

theViewModel doesn't have to come from the resources section, it could be a property in the hosting XAML control/page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜