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}".
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).
MarkMonster
Star
7622 Points
1505 Posts
Binding a property to it's parent
Jan 22, 2010 02:43 PM | LINK
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.
Blog
Silverlight and Expression Insiders UG
Dont forget to click "Mark as Answer" on the post that helped you.
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
MarkMonster
Star
7622 Points
1505 Posts
Re: Re: Binding a property to it's parent
Jan 22, 2010 05:22 PM | LINK
Blog
Silverlight and Expression Insiders UG
Dont forget to click "Mark as Answer" on the post that helped you.
Will_
Member
358 Points
64 Posts
Re: Binding a property to it's parent
Jan 23, 2010 09:20 AM | LINK
Hi,
Check this out http://www.codeproject.com/Articles/36500/Implementing-RelativeSource-binding-in-Silverlight.aspx.
Regards,
Will
binding relativesource