Solved

WPF: Reference to a "cousin" element

Posted on 2010-08-19
8
482 Views
Last Modified: 2013-11-12
Hi!

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

Simplified architecture:
StackPanel
-->StackPanel
----->GridView
----->....
--->StackPanel
------>textobxes

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!
0
Comment
Question by:Nargzul
8 Comments
 
LVL 18

Expert Comment

by:Anil Golamari
ID: 33475875
0
 
LVL 5

Expert Comment

by:berXpert
ID: 33482304
You may try to define a CollectionViewSource, as explained in Bea Stollnitz page:

http://bea.stollnitz.com/blog/?p=387

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

Definition cab be done in XAML.
0
 
LVL 1

Author Comment

by:Nargzul
ID: 33482642
@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
0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
LVL 5

Expert Comment

by:berXpert
ID: 33593649
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
<Window
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	x:Class="WpfApplication1.MainWindow"
	x:Name="Window"
	Title="MainWindow"
	Width="640" Height="480" mc:Ignorable="d">

	<Window.Resources>
		<DataTemplate x:Key="ItemTemplate">
			<Border Width="215.25" Height="44.92" BorderBrush="#FF24C94D" BorderThickness="2">
				<Grid>
					<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>
			</Border>
		</DataTemplate>
	</Window.Resources>

	<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">
				<StackPanel>
					<ListBox Name="MyList" Margin="0,0,-2,0" Height="205" ItemTemplate="{DynamicResource ItemTemplate}" ItemsSource="{Binding Collection}"/>
				</StackPanel>
			</Border>
			<Border Margin="20,0,59,0" Height="118" BorderBrush="#FF610909" BorderThickness="1">
				<StackPanel>
					<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}"/>
				</StackPanel>
			</Border>
		</StackPanel>
	</Grid>
</Window>

Open in new window

Q-26414613.jpg
0
 
LVL 1

Author Comment

by:Nargzul
ID: 33594033
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
0
 
LVL 2

Expert Comment

by:balbirsingh1976
ID: 34527015
Did you try RelativeSource in WPF? i think that can work for you.
0
 
LVL 1

Accepted Solution

by:
Nargzul earned 0 total points
ID: 34532380
Yeah. The solution was to set from the code behind the datacontext to THIS, and access to a property.
0
 
LVL 1

Author Closing Comment

by:Nargzul
ID: 34613410
found myself the solution
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Having Trouble with MS Access 2010 CommandBars 19 97
Windows Installer 4 72
GUI: DIalog Stacking and Popping in MS C++ 4 76
Question to Pivot table 1 53
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question