How to add DataContext to User Control's XAML?

How to add DataContext to User Control's XAML?

I have a user control MyControl, it needs to be bound to its view model: MyControlViewModel. I have no problem to add the DataContext programmically in the constructor. But I was told this  is not allowed. It has to be done in the XAML. However, I have gotten the error in XAML

MyControlViewModel is in the project MyProject.ViewModel

<UserControl  .....
        <local:MyControlViewModel/>        // ERROR: The name MyControlViewModel does not exist in the namespace "clr-namespace:MyProject.ViewModel"  


      // Style stuff...


Anyone can help me?

Thanks a lot.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Can you please add the assembly name and check. Open the assembly in object explorer  and check whether the class you are looking for is available.

<UserControl  .....
   xmlns:local="clr-namespace:MyProject.ViewModel, <assembly name>"
chuang4630Author Commented:
I have tried and it does not work. I end it up by implementing it in code behind

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chuang4630Author Commented:
I have a right solution
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.