0

I have earlier asked how to convert static values of TextBlocks using bindings and IValueConverter as seen here.

Now I would like to do the exact same thing, but with buttons instead. But the problem is, that buttons do not have the DataContext property, so the IValueConverter is not invoked.

So how do I achieve this?

Thank you!

Community
  • 1
  • 1
Zappel
  • 1,612
  • 1
  • 22
  • 37

2 Answers2

2

How about setting the

Button.Content.DataContext 

?

EDIT: XAML sample fixed

<Button Name="mmmm" 
        DataContext="{Binding MovieContext}" 
        Content="{Binding Title}" />
Igor Ralic
  • 14,975
  • 4
  • 43
  • 51
0

Buttons do have a DataContext property. All FrameworkElements do. Why not just set the datacontext of the Page that all of these are in? If you set the DataContext of the page to be a backing ViewModel, then every control will inherit that DataContext.

Shawn Kendrot
  • 12,425
  • 1
  • 25
  • 41