WPF: Reference to a "cousin" element


I search how to bind my data context to a cousin:

Simplified architecture:

how my textboxes can get the reference to the gridview? I have to do this xaml side!

I tried ElementName, but it can't find it :(

Thank you!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You may try to define a CollectionViewSource, as explained in Bea Stollnitz page:


CollectionViewSource can be used to sort, filter, group or track the current item, like in your sample.

Definition cab be done in XAML.
NargzulAuthor Commented:
@lucky85: I can't have a static resource, it's my code behind I want to reach, and data aren't loaded in constructor they are loaded dynamically when my usercontrol is loaded by his creator. It have to load data from my code behind, that is already existing and cannot be created from the xaml like you do

@berXpert: seems interessting, but are these 3 collections dependant form each other???

object Collection 1
--Object collection 2
----Object Collection 3
----Object Collection 3
----Object Collection 3
--ObjectCollection 2

The goal is to have some bind on the current element of the gridview
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

What element are you using for the GridView?

Does your GridView has a name?

Can you post your code?

I built a sample master - detail based on your information. I was able to get details from an ItemSource as a "cousin" element outside of the stack, attached sample code and picture
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	Width="640" Height="480" mc:Ignorable="d">

		<DataTemplate x:Key="ItemTemplate">
			<Border Width="215.25" Height="44.92" BorderBrush="#FF24C94D" BorderThickness="2">
					<TextBlock Text="{Binding Name}" VerticalAlignment="Top"/>
					<CheckBox IsChecked="{Binding Property2}" HorizontalAlignment="Left" Margin="31.75,0,0,8" VerticalAlignment="Bottom" Width="69.25" d:LayoutOverrides="Width"/>

	<Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SampleDataSource}}">
		<StackPanel Margin="63,34,65,65">
			<Border Margin="20,0,59,0" Height="215" Background="#FFBFCE2E" BorderBrush="#FF681818" BorderThickness="1">
					<ListBox Name="MyList" Margin="0,0,-2,0" Height="205" ItemTemplate="{DynamicResource ItemTemplate}" ItemsSource="{Binding Collection}"/>
			<Border Margin="20,0,59,0" Height="118" BorderBrush="#FF610909" BorderThickness="1">
					<TextBox Text="{Binding Path=SelectedItem.Name, Mode=OneWay, ElementName=MyList}" TextWrapping="Wrap"/>
					<TextBox Text="{Binding Path=SelectedItem.Number, Mode=OneWay, ElementName=MyList}" TextWrapping="Wrap"/>
					<Image Height="100" Source="{Binding SelectedItem.Photo, ElementName=MyList, Mode=Default}"/>

Open in new window

NargzulAuthor Commented:
In fact it seems the problem is because I'm using a RadDocking below, and the raddocking works almost like a different windows

These are component of telerik
Did you try RelativeSource in WPF? i think that can work for you.
NargzulAuthor Commented:
Yeah. The solution was to set from the code behind the datacontext to THIS, and access to a property.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NargzulAuthor Commented:
found myself the solution
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.