5

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 way around this error? Do I have to make my pages controls?

Thanks, Roy

LPCRoy
  • 935
  • 2
  • 12
  • 19
  • I'n not surprised this doesn't work in 4.0, I'm confounded that it does in 3.5. Do I understand your question correctly? – Guge Nov 25 '09 at 13:26
  • What's the misuderstanding? I defined a datatype as a page. I saw this in some MVVM tutorial a while back. – LPCRoy Dec 01 '09 at 00:19

2 Answers2

1

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...

H.B.
  • 166,899
  • 29
  • 327
  • 400
0

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.

Community
  • 1
  • 1
Jerther
  • 5,558
  • 8
  • 40
  • 59