Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

how to populate an explicitely loaded DataTemplate?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lloyd Dupont - 24 Jul 2007 03:34 GMT
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.
Laurent Bugnion, MVP - 28 Jul 2007 21:23 GMT
Hi,

> 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
[quoted text clipped - 17 lines]
> 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/library/system.windows.data.binding.aspx

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

Is that what you're after?

HTH,
Laurent
Signature

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

Lloyd Dupont - 30 Jul 2007 00:56 GMT
> Databinding in code is done using the Binding class:
> http://msdn2.microsoft.com/en-us/library/system.windows.data.binding.aspx
[quoted text clipped - 3 lines]
>
> 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)
Laurent Bugnion, MVP - 30 Jul 2007 08:54 GMT
Hi,

> --- get the data ---
> IDataObject ido = ......;
[quoted text clipped - 6 lines]
> 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
Signature

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

Lloyd Dupont - 30 Jul 2007 14:12 GMT
> 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.... ;-)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.