Dynamically load in script/code and tie it to bindings

Go To StackoverFlow.com

1

I'm not sure how to approach this or if it is even feasible. I am tracking a users hand position and have say their left hand's x and y position. What I would like to be able to do is dynamically load in some loose xaml code which has say a square on a canvas. The position of the square would be bound to the x and y of the user's hand.

Is this possible? And if so, some pointers on where to begin?

2012-04-04 04:33
by benjgorman
First, you need whatever device that tracks the hand movement to have a public event that is raised every time the X and Y changes. Afterward simply create your WPF, and subscribe to the event of your device. Then it's easy, update the Canvas position based on the new X and Y input that is either sent with the Event or that you're accessing in the Event - Alexandre 2012-04-04 04:48
Yup I can do all that, what I want do do is dynamically load in some WPF xaml code and be able to bind to the x and y input - benjgorman 2012-04-04 04:54
I'm not sure I fully understand why you would need/want to do that? I Guess the device can handle two hands at Once and so you'd want two Canvas in this case - Alexandre 2012-04-04 05:01
I don't think I'm being clear enough. I have the variables for the hands, I have an empty content control in the WPF App, I want to dynamically load a xaml file or something similar which defines a user control which binds to these variables and events - benjgorman 2012-04-04 05:06
By dynamic I mean literally load some loose xaml from disc - benjgorman 2012-04-04 05:09


0

DataTemplate and Trigger are what you're looking for.

Data Templating Overview on MSDN

Really good example on Code Project

Basically you'll want to create a DataTemplate for your Input and add Triggers for your X & Y Attributes so that you can move the Canvas so the right Location.

This will also support a dynamic amount of input (1,2,3,etc hands).

Good luck!

2012-04-04 05:07
by Alexandre
This isn't what I'm looking for. See the additional comment I just added : - benjgorman 2012-04-04 05:11
The right approach would be DataTemplate, given you have all the variables at hands. That's as far as my knowledge goes but you can check this link out: Load XAML at RuntimeAlexandre 2012-04-04 05:15
That link is kinda more what I am looking for. Cheers - benjgorman 2012-04-04 18:37
Ads