Moving from WPF 3.5 to 4.0 causes error "Can't put a page in a Style"
I'm in the process of moving my application from .NET 3.5 to .NET 4.0, and I get the following error message : "Can't put a page in a Style". I've implemented the MVVM pattern for this application and use Data Templates to tell the application how to render my various view models...for example below.
<DataTemplate DataType="{x:Type vm:ConfigureAxViewModel}">
<vw:ConfigureAxPage />
</DataTemplate>
Is there any w开发者_JAVA技巧ay around this error? Do I have to make my pages controls?
Thanks, Roy
Docs for both 3.5 & 4.0:
A page can be hosted from Window, NavigationWindow, Frame, or from a browser.
I would not expect a view that is a page to work in many instances for that matter, usually views are just UserControls
. Though i also would not expect that error message...
I happened to get this error in the designer in Visual Studio 2010. A couple of hours later with half of my hair gone, I found the problem in App.xaml
<DataTemplate DataType="{x:Type vm:LoginViewModel}">
<views:Login />
</DataTemplate>
(So where is the "Style" they talk about???) Anyways, here, Login is a Page. It turns out a Page can't be used here. You have to specify a DataContext in the page's xaml instead:
DataContext="{Binding LoginPage,Source={StaticResource Locator}}
Source
I'm using MVVM Light so you might want to check it out for more information about the Locator.
精彩评论