Seeing ViewModel Properties when Binding

Feb 16, 2014 at 6:58 PM
This is for the new Prism 4.2, but not an item to selected below.

I noticed there were some new features added in VS 2013 for XAML and binding. One was to be able to see the properties of item that was bound to the UI component. As an example, if I had a Person Class bound to a Grid with TextBlocks, I should be able to see properties (e.g. FirstName, LastName, etc.) in the XAML when typing <TextBlock Text={Binding ...

I thought with the new locator and features within would work with the new bits. It still works and will be displayed in the UI. I'm I missing something?

Feb 17, 2014 at 6:48 PM
Hi shaggygi,

I believe you wanted to say that Binding IntelliSense is still not working for you. Based on my understanding, there are a few things that need to be declared in order to make IntelliSense work:

  • Data Context should be defined in View's Xaml code without being injected from the container. So it would be available for DesignTime and Binding can resolve the Properties with IntelliSense. Local namespace declaration would be needed to reference the DataContext.
  • Also, you would need to declare the following namespaces for the proper IntelliSense to work:
Bear in mind that declaring the DataContext directly into xaml code couples the View with its ViewModel/Model and the container is not able to resolve any dependency from it. Therefore, one possible way to solve this would be to declare a Mock ViewModel which implements every property into xaml code, and resolve the proper ViewModel from the container.

I hope this helped you,

Gabriel Ostrowsky.
Feb 18, 2014 at 1:47 AM
Yes, that is exactly what I was trying to explain. Thanks for the help.
Feb 18, 2014 at 4:50 PM
We make a property in the view that is the same type of the viewmodel that will be injected in and set that property as the datacontext in xaml. We do tie our views to the viewmodel but not the viewmodel to the view. Then we constructor inject the same type and store it to the property.

Example: of the code behind
public partial class DashboardView
        public DashboardViewModel ViewModel { get; set; }

        // need empty constructor for the design time but unity will inject into the other constructor
        public DashboardView()

        // At run time unity will use this constructor
        public DashboardView(DashboardViewModel viewModel)
            ViewModel = viewModel;
Example of the Xaml
<UserControl x:Class="DashboardView"
      DataContext="{Binding RelativeSource={RelativeSource Self}, Path=ViewModel}">
I haven't tried this in VS 2013 but we use Resharper in VS 2012 and it picks up the datacontext this way. I would hope it works in VS 2013.