Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Binding a property to it's parent RSS

3 replies

Last post Jan 23, 2010 09:20 AM by Will_

(0)
  • MarkMonster

    MarkMonster

    Star

    7622 Points

    1505 Posts

    Binding a property to it's parent

    Jan 22, 2010 02:43 PM | LINK

    Let's start with explaining the situation. I have a DataContext with the following properties.

    DataContext.Tags (IEnumerable of Tag)
    DataContext.Command (Command to execute when a Tag is clicked)


    Alright I've put the Tags in a Repeating thing (TagCloud). By using the following ItemsSource="{Binding Tags}". Works like a charm, I can now put for example the following expression in the template to show the name of each tag:Content="{Binding Name}"


    I wanted to bind to the parent Command but couldn't find anything on how to do this, also the command parameter would be like CommandParameter="{Binding}".

    I hope someone can help me out.
    Mark Monster - Silverlight MVP - MCPD Enterprise
    Blog
    Silverlight and Expression Insiders UG

    Dont forget to click "Mark as Answer" on the post that helped you.
  • Will_

    Will_

    Member

    358 Points

    64 Posts

    Re: Binding a property to it's parent

    Jan 22, 2010 02:57 PM | LINK

    Hi,

    you could try

    CommandParameter={Binding Path=DataContext.Command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type XXX}}}

    where XXX is the type of the parent control (like x:ItemsControl etc etc).

    Regards,
    Will

    MCSD, MCPD, .NET Developer
  • MarkMonster

    MarkMonster

    Star

    7622 Points

    1505 Posts

    Re: Re: Binding a property to it's parent

    Jan 22, 2010 05:22 PM | LINK

    Not that bad an idea. But sadly this doesn't work on Silverlight, but for WPF this would be the answer.
    Mark Monster - Silverlight MVP - MCPD Enterprise
    Blog
    Silverlight and Expression Insiders UG

    Dont forget to click "Mark as Answer" on the post that helped you.
  • Will_

    Will_

    Member

    358 Points

    64 Posts

    Re: Binding a property to it's parent

    Jan 23, 2010 09:20 AM | LINK

    binding relativesource

    MCSD, MCPD, .NET Developer