locked
Inherit Color From The Parent RRS feed

  • Question

  • I have two SL xaml. The Parent and its child.

    Is it possible to set the child color from the parent? How can I do?

    The child is created from xaml parent in this way.


    <customControls:MyControls Foreground="Red" />


    Thank you in advance. Regards.

    EDIT: My goal is to bind the parent foreground to the child controls. For example, the child has some controls and these controls have to inherit the foreground color.

    This is the child UserControl:

    <UserControl>
    
      <Grid>
    
        <internalControl:MyContent Foregorund={BindToRedColorHereFromParent} />
    
      </Grid>
    
    </UserControl>



    Tuesday, May 31, 2011 5:13 AM

Answers

  • Hi

    I am assuming that your MyControl is defined as:

    <UserControl>
    
      <Grid>
    
        <internalControl:MyContent :Name="Child" Foregorund={BindToRedColorHereFromParent} />
    
      </Grid>
    
    </UserControl>

    Now in the code behind of the Parent control bind the child control's foreground property with Parent's foreground property, something like this:

    Child.SetBinding(ForegroundProperty, new Binding { Source = this, Path = new PropertyPath("Foreground")});



     

    Tuesday, June 7, 2011 3:53 AM

All replies

  • You cannot bind parent control to child control directly in your case. 

    Monday, June 6, 2011 10:09 AM
  • Hi

    I am assuming that your MyControl is defined as:

    <UserControl>
    
      <Grid>
    
        <internalControl:MyContent :Name="Child" Foregorund={BindToRedColorHereFromParent} />
    
      </Grid>
    
    </UserControl>

    Now in the code behind of the Parent control bind the child control's foreground property with Parent's foreground property, something like this:

    Child.SetBinding(ForegroundProperty, new Binding { Source = this, Path = new PropertyPath("Foreground")});



     

    Tuesday, June 7, 2011 3:53 AM
  • Why don't you make it transparent?

    Tuesday, June 7, 2011 5:38 AM