Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

how to populate an explicitely loaded DataTemplate?

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 07-23-2007   #1 (permalink)
Lloyd Dupont
Guest


 

how to populate an explicitely loaded DataTemplate?

I am working on some drag and drop code.
When some data is moved over a target which accept it I want to show a data
preview.

For this I attempt to create an UIElement with the default DataTemplate.
Problem is, I don't know how to setup the UIElement returned by the
DataTemplate! (i.e. setup it binding correctly)

===== pseudo code: =======
IDataObject ido = ......;
object data = ido.GetData("some key");
FrameworkElement target = sender as FrameworkElement;
DataTemplate dt = target.FindResource(data.GetType()) as DataTemplate;
UIElement ui = dt.LoadContent() as UIElement;

// NOW HOW DO I SET UP DATA BINDING?
ui.....= .....
==================

PS: I do need to get the UIElement, as I measure it to position it
relatively to the mouse position.


My System SpecsSystem Spec
Old 07-28-2007   #2 (permalink)
Laurent Bugnion, MVP
Guest


 

Re: how to populate an explicitely loaded DataTemplate?

Hi,

Lloyd Dupont wrote:
> I am working on some drag and drop code.
> When some data is moved over a target which accept it I want to show a
> data preview.
>
> For this I attempt to create an UIElement with the default DataTemplate.
> Problem is, I don't know how to setup the UIElement returned by the
> DataTemplate! (i.e. setup it binding correctly)
>
> ===== pseudo code: =======
> IDataObject ido = ......;
> object data = ido.GetData("some key");
> FrameworkElement target = sender as FrameworkElement;
> DataTemplate dt = target.FindResource(data.GetType()) as DataTemplate;
> UIElement ui = dt.LoadContent() as UIElement;
>
> // NOW HOW DO I SET UP DATA BINDING?
> ui.....= .....
> ==================
>
> PS: I do need to get the UIElement, as I measure it to position it
> relatively to the mouse position.


Databinding in code is done using the Binding class:
http://msdn2.microsoft.com/en-us/lib...a.binding.aspx

There is an example here:
http://msdn2.microsoft.com/en-us/library/ms742863.aspx

Is that what you're after?

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
My System SpecsSystem Spec
Old 07-29-2007   #3 (permalink)
Lloyd Dupont
Guest


 

Re: how to populate an explicitely loaded DataTemplate?

> Databinding in code is done using the Binding class:
> http://msdn2.microsoft.com/en-us/lib...a.binding.aspx
>
> There is an example here:
> http://msdn2.microsoft.com/en-us/library/ms742863.aspx
>
> Is that what you're after?
>

Not really, but....

1. thanks for answering
2. I found what I need:

--- get the data ---
IDataObject ido = ......;
object data = ido.GetData("some key");

--- show it with the default template ---
ContentControl c = new ContentControl();
c.Content = data;

c.Content could be anything, unlike what the documentation states (UIElement
or string)

My System SpecsSystem Spec
Old 07-30-2007   #4 (permalink)
Laurent Bugnion, MVP
Guest


 

Re: how to populate an explicitely loaded DataTemplate?

Hi,

Lloyd Dupont wrote:
> --- get the data ---
> IDataObject ido = ......;
> object data = ido.GetData("some key");
>
> --- show it with the default template ---
> ContentControl c = new ContentControl();
> c.Content = data;
>
> c.Content could be anything, unlike what the documentation states
> (UIElement or string)


I just understood what you were trying to do!! Sorry for not getting it
faster :-)

Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
My System SpecsSystem Spec
Old 07-30-2007   #5 (permalink)
Lloyd Dupont
Guest


 

Re: how to populate an explicitely loaded DataTemplate?

> I just understood what you were trying to do!! Sorry for not getting it
> faster :-)
>

No worries!
My explanations might have been confusing I admit.... ;-)


My System SpecsSystem Spec
Closed Thread
Update your Vista Drivers Update Your Drivers Now!!

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
DataTemplate Billy Jacobs .NET General 0 05-12-2008 10:36 AM
Cannot retrieve the visualtree from a datatemplate Pon Avalon 1 02-01-2007 08:20 AM
What is the difference between DataTemplate and ControlTemplate Daniel Avalon 4 05-19-2006 03:19 AM
Why can't I have a grid inside a datatemplate? Philippe Lavoie Avalon 1 03-22-2006 09:55 PM
Accessing Named controls within a datatemplate Midas Avalon 0 01-10-2006 03:53 PM



Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008