Marcom
Marcom

Reputation: 4751

Databinding to a property in code behind but with a different datacontext

Is there a way to databind to a property in the codebehind of a wpf control, while having a different datacontext??

Upvotes: 0

Views: 132

Answers (1)

blindmeis
blindmeis

Reputation: 22445

for every binding you can set the source explicitly. You can use StaticResource or RelativeSource to get where you want.

 <TextBlock DataContext="{Binding MyDataContext}" Text="{Binding Source={StaticResource MyOtherDataContext} Path=PropertyFromOtherDataContext}" />

Upvotes: 2

Related Questions