views:

39

answers:

1

Quick 1 sentence summary: I wrote a demo app [download src here][1] that doesn't properly display sample data in the Visual Studio Designer and I need help.

After 6+ years developing in C# and WinForms, I've decided to use WPF in my current project. I've written a small demo application to teach myself and experiment with WPF (you can see a screenshot [here][1]). The app simply downloads and displays recent news stories from the Google News RSS feed.

My first attempt at this resulted in the class called "GoogleNewsWidget." After reading about the MVVM model, however, I tried again and built "GoogleNewsWidget2" that attempts to utilize a more MVVM-oriented architecture. I'm not sure which implementation is best as they both seem to be working fine on the whole (and though I'd appreciate comments on which is better, it is not my primary question).

My main problem is that neither play very well with the Visual Studio Designer. The GoogleNewsWidget2 loads and displays data fine when its xaml is opened directly but does not display correctly when embedded into another xaml file . The GoogleNewsWidget does not display data in the Designer in either case.

Any help would be appreciated. Again, the source is available for download [here][1].

Thanks,

Jon

[1]: http://abstract.cs.washington.edu/~jfroehli/reflect/ Demo App Source Code

PS My original post had multiple hyperlinks to screenshots but its posting was denied by StackOverflow for spam prevention reasons. Thus, I created the [1] url, which contains screenshots and a link to source code. If someone could also help me figure out how to use the "Markdown" language for linking, I'd be grateful. :)

A: 

Assuming that the VS2010 designer works the way Blend 3 does, you have to provide "dummy" data -- the designer won't pull data from external sources.

Create an object that implements the same interface as your datasource (view model) and fill it with static data. Make sure it has a public, no-arg constructor.

Define it as a resource in your control, giving it a key like "DesignData".

In the root element of your control, add the attribute d:DataContext={DynamicResource DesignData}"

This will be used as the DataContext only when in the designer.

Jay
Jay, thanks so much for your response. However, your answer does not seem to respond directly to my problem, at least in the case of GoogleNewsWidget2. Remember, in this case, I can actually see the dummy data in the VS2010 designer when I open GoogleNewsWidget2.xaml but NOT when I put GoogleNewsWidget2 into another xaml file, for example, a window (as I do in the code I posted, I place the GoogleNewsWidget2 into MainWindow.xaml). In MainWindow.xaml, the dummy data no longer shows. But why?
andicolortoo