views:

523

answers:

1

Ok, so I have a general question about WPF. I've messed a little with ASP.NET MVC and in the markup it has intellisense on your viewmodel object so you don't mistype it( i love it).

Enter WPF, I love it, I'm utilizing the MVVM approach and one annoying thing that I have to do is make sure I'm binding correctly to my viewmodel. So I type something up in my xaml, then I either 1) if I'm lazy just run the app and click around 2) If i'm not lazy a)Look at the current DataContext of the control I'm working with. b)Go to that ViewModel class look at the properties c)Find my property and then click back to my view and make sure that I spelled it correctly.

I believe that you can look at your trace output for incorrect bindings at run time, but is there something in the horizon to allow intellisense in xaml. The View needs to know about my ViewModel, so why not expose that in xaml.

I think it would be nice for the IDE to do that for me, meaning, when I type "{Binding " it should go up the visual tree find the first non-null DataContext and display the properties, let me select one and there you have it.

Am I missing something? Are there any alternatives. Any insight?

EDIT:

Regarding the comments below there is a way to set the datacontext at design time e.g.

<Window.Resources>
    <DesignTimeData:DesignTimeCustomers x:Key="designTimeCustomersDS" />
</Window.Resources>

which is a snippet from this blog: http://karlshifflett.wordpress.com/2008/10/11/viewing-design-time-data-in-visual-studio-2008-cider-designer-in-wpf-and-silverlight-projects/

All it does is reference a class within xaml.

So with that in place could not the designer then utilize reflection on the datacontext to give you all of the properties for that class?

+3  A: 

Visual Studio 2010 will support intellisense on Bindings. However, this is limited to the properties of the Binding object itself. For example after typing "{Binding " into the XAML editor I then get intellisense on the remaining properties (Path, ElementName, etc.).

I don't think the type of intellisense regarding the data context you specified would be possible as the data context is set at run-time. I've tried experimenting in VS 2010 by setting the data context directly in the constructor but did not have any luck.

Richard C. McGuire
Here's the link for the MIX09 video that goes over some of this, fast forward to around 20min to get into the Resource Picker and intellisence: http://videos.visitmix.com/MIX09/T73M
rmoore
Given that the DataContext is set a run time, I doubt that it's possible to implement intellisense for bindings, unfortunately. Just because the type of the variable set as the DataContext is Foo, it could really be a Bar and Bar's properties are fair game to use for bindings. How could Visual Studio know this to be the case?
Andy
I made some updates above that basically indicates that we can assign the datacontext in design time. But from your comments, it seems this isn't on the horizon.
Jose