![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| DataTemplate | .NET General | |||