Hey guys,

I am setting my viewmodel as datacontext in my xaml but I override it to my view to make few functions work however to achieve the visibility on some grids and I have a property in my VM can I override my datacontext back to my VM? If so how? I have a stackpanel that has datacontext overriden as my grid and within that stackpanel I need to change the datacontext for a button.

Any help will be appreciated thanks

6 Years
Discussion Span
Last Post by pfaux12

The problem is that you have switched data contexts so your xaml code doesn't know anything about your property in the viewmodel. You will have to do a RelativeSource binding, something like this:

{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type YourView}}, Path=yourProperty}
Votes + Comments
fixed my problem thanks
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.