tags:

views:

25

answers:

1

I have this block of xaml and I made a ViewModel which contains a property called MyBrush. I would like to set the grid background to that property but this block doesn't work. Could you tell me how can I do that?

<Style x:Key="myKey" TargetType="myType">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="myType">
        <Grid Background="{Binding RelativeSource={RelativeSource Self},
                                   Path=MyBrush}">
...
+1  A: 

I think what you want is templatebinding, its another markup extention used to bind when in a template, see this article for more .However when you mention viewmodel im thinking your using it as a datacontext, if thats the case just use binding without the relativeSource expression as this is saying bind to the grid and look for property mybrush, which is a property that grid doesnt have.

almog.ori