Solved

DataTemplate question...

Posted on 2010-08-12
3
308 Views
Last Modified: 2013-11-12
Hello

I have a listbox with my own custom DataTemplate. On it, I have several items which are bound to some class.
One of the items is a StackPanel. Now I have a question about this. I have created a Parser which is converting a string (XML) into a Stackpanel, which is containing several, dynamic, elements. Now I want to set, that the Stackpanel on the DataTemplate is this stackpanel.

Usually, I am binding some attribute (e.g. Text) to a class, sometimes using a Converter. But how can I bind a whole StackPanel to a StackPanel, replacing it?

Or what different approach do I have to take?

Thank¨s a lot
0
Comment
Question by:Ruttensoft
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
unmeshdave earned 500 total points
ID: 33430748
you can use resource dictionary . In WPF/SL, you can dyanmically add resource dictionary to your program and add dynamic reference to any visual object you want.
like you want to create XML, better to create XAML with resource dictionary definitions inside it, and in your program when you want to add this resource dictionary(i guess you want to use it dynamically), you add this resource dictionary by calling mergedictionaries on current resourcedictionary.
every visual object in resource dictionary will have 'Key' attribute, which you can use to reference.
following link somewhat provides info about what I am saying,
http://blogs.msdn.com/b/wpfsdk/archive/2007/06/08/defining-and-using-shared-resources-in-a-custom-control-library.aspx 
0
 

Author Comment

by:Ruttensoft
ID: 33430765
Hm, I solved it with replacing the Stackpanel on the DataTemplate with a ContentPresenter, and then I am binding the Stackpanel to the Source of the ContentPresenter... That's all...
0
 
LVL 8

Assisted Solution

by:unmeshdave
unmeshdave earned 500 total points
ID: 33430809
ok that is static binding, I was under impression that you want to do it dynamically I mean at runtime. :) all the best. you can close this question as it is already solved.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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