Click here to Skip to main content
13,298,175 members (76,173 online)
Rate this:
Please Sign up or sign in to vote.
In order to enable drag-drop properly between two user controls, I need to call their viewmodels from the MainWindow viewmodel

I had thought that it would be as simple as this:

<UserControl x:Class="LookupTermWizard.View.Properties"
        Height="300" Width="500" removed="LightGray" DataContext="{Binding}" >

<Window x:Class="LookupTermWizard.MainWindow"
        Title="Lookup Term Wizard" Height="900" Width="1300">
        <vm:MainWindowViewModel />
        <StackPanel DockPanel.Dock="Left" VerticalAlignment="Top" Height="775" >
                <v:Properties DataContext="{Binding PropertiesVM}" />

And then instantiate the viewmodel for the user control from the MainWindowViewModel

        PropertiesViewModel propertiesVM;
        PropertiesViewModel PropertiesVM
            get { return propertiesVM; }
                propertiesVM = value;
        public MainWindowViewModel()
            PropertiesVM = new PropertiesViewModel();

Of course, it doesn't work that way. Any chance of getting some guidance?
Posted 21-Sep-12 8:30am
Matt T Heffron 21-Sep-12 18:23pm
So what is going wrong? Binding failing?
(I noticed that PropertiesVM is not shown here as public...)
You shouldn't use the DataContext={Binding} in the Properties XAML. The DataContext has been explicitly set in the MainWindow.
(Also, since v:Properties is a UserControl, why wrap it in ContentControl?)
Bob Brady 24-Sep-12 8:53am
Oh, my God, I'm stupid. Yes, the problem was that I left public off of the PropertiesViewModel. I can't believe that. That's what I get for working late on a Friday, huh?

Thanks, Matt.

As for the UserControl - that's the only way I know of to invoke it. I've been a WPF/MVVM programmer for about 3 weeks. Normally I do websites.
Member 11248861 13-Aug-15 1:53am
Thanx alot I got this doing for me same problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171207.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100