WPF-Can a XAML object be a source as well as a target for bindings?
Posted
by
iambic77
on Stack Overflow
See other posts from Stack Overflow
or by iambic77
Published on 2011-01-07T11:51:50Z
Indexed on
2011/01/07
11:53 UTC
Read the original article
Hit count: 271
wpf
|wpf-binding
I was wondering if it's possible to have a TextBlock as a target and a source?
Basically I have a bunch of entities which have simple relationships to other entities (like Entity1 Knows Entity3, Entity3 WorksAt Entity2 etc.)
I have a Link
class that stores SourceEntity
, Relationship
and TargetEntity
details.
What I want to be able to do is to select an entity then display the relationships related to that entity, with the target entities of each relationship listed underneath the relationship names.
When an entity is selected, an ObservableCollection
is populated with the Links
for that particular entity (SelectedEntityLinks<Link>
).
Because each entity could have the same relationship to more than one target entity (Entity1 could know both Entity3 and Entity4 for eg.), I've created a method GetThisRelationshipEntities()
that takes a relationship name as a parameter, looks through SelectedEntityLinks
for relationship names that match the parameter, and returns an ObservableCollection
with the target entities of that relationship.
Hope I'm making this clear.
In my xaml I have a WrapPanel
to display each relationship name in a TextBlock:
<TextBlock x:Name="relationship" Text="{Binding Path=Relationship.Name}" />
Then underneath that another Textblock which should display the results of GetThisRelationshipEntities(String relationshipName).
So I want the "relationship" TextBlock to both get its Text from the binding I've shown above, but also to provide its Text as a parameter to the GetThisRelationshipEntities()
method which I've added to <UserControl.Resources>
as an ObjectDataProvider.
Sorry if this is a bit wordy but I hope it's clear. Any pointers/advice would be great.
Many thanks.
© Stack Overflow or respective owner