473,508 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[WPF] Data Binding Hierarchy Issue

EARNEST
128 New Member
Hello everybody,

I am new to WPF, and trying to develop a small application using DataBinding following the MVVM paradigm.

I am trying to provide a binding functionality to the ObservableCollection of Documents (my type). The First Label would display a Documents path (available through Attribute property), while the next children - Pages of the Documents - would display appropriate information: page index and page content (an image).

Here is an issue - how can I create a lookup binding to a parent Label? On Button Click command I would like to pass the documents path, which was available earlier in the first DataTemplate.

Is there a way to tackle this issue?
How would you recommend going around it?

Also, is there a better way to tackle "nested" structures (collections within collections)?

Thanks in advance.

Expand|Select|Wrap|Line Numbers
  1. <ItemsControl ItemsSource="{Binding Documents}">
  2.     <ItemsControl.ItemTemplate>
  3.         <DataTemplate>
  4.             <StackPanel>
  5.                 <Label Content="{Binding Path=Attribute.Path}"/>
  6.                     <ItemsControl ItemsSource="{Binding Pages}">
  7.                         <ItemsControl.ItemTemplate>
  8.                             <DataTemplate>
  9.                                 <StackPanel>
  10.                                     <Label Content="{Binding Index}"/>
  11.                                     <Button Content="{Binding Content}"
  12.                                             Command="{x:Static viewModel:DocViewModel.Tests }" 
  13.                                             CommandParameter="{Binding Path=Attribute.Path}"/> 
  14.                                 </StackPanel>
  15.                             </DataTemplate>
  16.                         </ItemsControl.ItemTemplate>
  17.                     </ItemsControl>
  18.                 </StackPanel>
  19.             </DataTemplate>
  20.         </ItemsControl.ItemTemplate>
  21. </ItemsControl>    
  22.  
Dec 3 '12 #1
1 2102
EARNEST
128 New Member
I received a tip on this issue.

Expand|Select|Wrap|Line Numbers
  1. CommandParameter="{Binding Path=DataContext.Attribute.Path,RelativeSource={RelativeSource AncestorType=ContentPresenter, Mode=FindAncestor,AncestorLevel=2"/> 
  2.  
Dec 4 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1546
by: Cees Wesseling | last post by:
For a couple of years I am using now my own data binding tool that can create C++ classes from a DTD. At this moment I need to reconsider this tool since I want to use W3C XML Schemas and need to...
0
2319
by: Ann Morris | last post by:
INTRODUCTION One of the most powerful aspects of .NET and Windows Forms is data binding. Data binding is the process of associating user interface (UI) elements with a data source to generate a...
1
1210
by: PCC | last post by:
I am using the Infragistics UltraWebNavigator menu control and am having trouble building my menu hierarchy either by data binding or coding it manually. I have included a sample of my Menu table...
2
1328
by: Lori Markle via .NET 247 | last post by:
Hi, I already posted this but can't find it anywhere! I'm having a problem that seems very simple. I'm trying to updatea db and am getting stuck on the data binding of a textbox. Iget a "Cannot...
19
2315
by: Simon Verona | last post by:
I'm not sure if I'm going down the correct route... I have a class which exposes a number of properties of an object (in this case the object represents a customer). Can I then use this...
19
2206
by: Larry Lard | last post by:
In the old days (VB3 era), there was a thing called the Data Control, and you could use it to databind controls on forms to datasources, and so (as the marketing speak goes), 'create database...
2
3292
by: Lloyd Dupont | last post by:
I have a color chooser class class ColorPicker : Control { public byte R { get; set; } public byte G { get; set; } public byte B { get; set; } public Color Color { get; set; } } All are...
3
454
by: csharpula csharp | last post by:
Hello, I am trying to do data binding with c# Binding - trying to bind list<objectto a list view. Is there any code example for doing that? Thank you! *** Sent via Developersdex...
6
4577
by: Tomasz J | last post by:
Hello developers, I bind my TextBox control specyfying a format stored in my application global ApplicationContext object - it has a static string CurrencyFormat property. The problem - this...
2
4499
by: =?Utf-8?B?Q29sb3JzdG9uZQ==?= | last post by:
Hi, I have a TabContainer inside a data bound FormView (to logically group the form fields into different tabs). The display part of the data binding works fine, but the Update doesn't. ...
0
7120
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1553
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.