×

First time here?

You are looking at the most recent posts. You may also want to check out older archives. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS or email. Thank you for visiting!

i just put up my latest screencast featuring a sample on how to create your own user control in version 1.0.  this is about a 24 minute screencast that walks through creating the XAML as a user control (not the primary focus) quickly, and then consuming this user control in a silverlight 1.0 application, creating the control dynamically using createFromXaml.

i also realized that in the screencast i mentioned that i was using the 'open as web site' feature in visual studio 2008 instead of just right-clicking the project in blend and choosing 'edit in visual studio' -- but then didn't remember to explain why :-).  here's the skinny.  in my sample i'm using the downloader object in silverlight.  in the release candidate of silverlight there was a change to the downloader disallowing the use of the file:/// schema for downloads for security reasons.  unfortunately in visual studio 2008 (beta 2), the default project type for silverlight is a file-based project instead of a web site project.  this will work fine most of the time, but not when you are using a downloader object (you'll get an AG_CONTROL_NETWORK_ERROR).  so because of this i simply opened the same project as a web site and all is well (because it then uses the built-in asp.net development web server for rednering).

this is a part 1 screencast, which part 2 will demonstrate consuming the same user control in silverlight 1.1 which provides us an added benefit in the user control model.  you can view the screencast by subscribing to the feed (located on the left as well -- the all option has ipod format as well).  additionally i posted it on channel 9.

part 2 will be hopefully posted later on monday.  the code for part 1 is associated on this blog post at the bottom.

Screencast source code: GlassButtonControl.zip


8/20/2007 9:42 AM | # re: implementing silverlight controls in 1.0
Hi Tim,
This is great, i didnt know usercontrols were available for 1.0.

Could your downloader method, download a zip containing both the JS and xaml and uuse a createElement("script") function
to dynamically add the script as well.

Is there any way a designer can refernce these js controls in Blend?

I could see this being very popular. If so will silverlight.net provide a user control gallery to upload and share these?

Thanks
slyi
8/20/2007 10:23 AM | # re: implementing silverlight controls in 1.0
slyi: good question about the zip with JS/XAML in one -- i haven't tried it! as for a designer being able to use them, they'd be able to use the XAML since it is just XAML, but depending on their effective use at the end, it might require some XAML refactoring from the developer. part 2 helps solve this a bit more...stay tuned.
8/20/2007 11:28 AM | # re: implementing silverlight controls in 1.0
great stuff tim. obviously the glassbutton control should have a onclick event. how does one declare jscript events and attach eventhandlers? (or should i just sit tight and wait for part 2...)
8/20/2007 11:48 AM | # re: implementing silverlight controls in 1.0
koen: actually it does. the mouseleftbuttonup essentially is the result of a completed click. in this sample, i've already wired up an event just to demonstrate, but in your instantiation of the control you could wire up a new event using addEventListener() and putting your delegate there.
9/2/2007 2:08 PM | # re: implementing silverlight controls in 1.0
Tim.
I have been using your proposed pattern for a while now and found (and solved) an issue with circular references. Details over here: http://www.firstfloorsoftware.com/BlogPost.aspx?id=12100

Hope this helps
9/6/2007 10:39 PM | # re: implementing silverlight controls in 1.0
Any special reason of why you are downloading the Xaml from the page then creating a new GlassButton instance passing the Xaml fragment as a parameter?
Could you just create or download the Xaml from the GlassButton constructor?
I don't know, maybe in this example we can decouple that task from the page itself and implement it right in the GlassButton.

What do you think?
9/6/2007 11:29 PM | # re: implementing silverlight controls in 1.0
roky: no special reason and in fact i like your idea as well -- software is an art, many ways of doing it -- this was a stab at a first pattern i've been messing with
9/24/2007 5:37 PM | # re: implementing silverlight controls in 1.0
Can you elaborate a bit as to why you use Silverlight.createDelegate as opposed to just referencing a function name?

There doesn't seem to be a whole lot of documentation on createDelegate and I'm not sure what advantage it offers, and when one should choose to use that method instead of just a reference to a function name.

Thanks!
9/25/2007 11:32 AM | # re: implementing silverlight controls in 1.0
One more question: How is it that when you create multiple instances of the button there are no naming collisions? Since there will be n number of "ButtonReflex" (for example) when instantiating multiple buttons. How does Silverlight keep track of them all? I thought x:Name's had to be unique?

Same question applies to the Storyboards. They are only declared once, yet they somehow 'magically' know which named object (i.e. TargetName) to act upon even when there are multiple objects of the same name existing within the Silverlight app.

It's all very cool that you can do this, I just wish it was better documented somewhere on how this all is able to work.
Gravatar
10/3/2007 5:59 AM | # re: implementing silverlight controls in 1.0
can u tel how to write a the simplest program in silverlight.i m very new to this. plz tell the steps t follow in .NET VS8. and silverlight,
10/3/2007 9:51 AM | # re: implementing silverlight controls in 1.0
Jason: For your second question, Tim is taking advantage of namescopes. The key part is calling createFromXaml with true as the second arguement. This puts each element in a separate namescope, thus avoiding name collisions. Read about namescopes at http://msdn2.microsoft.com/en-us/library/bb687963.aspx
1/4/2008 2:44 AM | # re: implementing silverlight controls in 1.0
I really wanna thank and appreciate for this wonderful video. I am newbie to JavaScript and wondering how to create multiple instances for a single Silverlight 1.0 custom control as I was trying to create a Silverlight 1.0 TextBox control and I am so happy that your video helped me a lot. Thanks again.
1/10/2008 5:42 AM | # re: implementing silverlight controls in 1.0
I come to say thanks for your video, and here I find the code,bye the way ,I'm from China.:非常感谢你的视频,我在你的博客里找到你的代码,呵呵,我来自中国。I am not sure whether you can undersstand it....
1/21/2008 9:41 AM | # re: implementing silverlight controls in 1.0
Lijian, can you send me that link on my email. I'm new in this subject and this could really help me.
2/12/2008 9:30 AM | # re: implementing silverlight controls in 1.0
Hi tim !! it was great work but how can we reuse these controls in ASP.NET web application.
2/12/2008 1:50 PM | # re: implementing silverlight controls in 1.0
silverlight controls can't be directly used in asp.net (as asp.net controls) but you can wrap them in a lightweight silverlight host and make them a part of your app.

 
Please add 4 and 7 and type the answer here:

DISCLAIMER:

The opinions/content expressed on this blog are provided "ASIS" with no warranties and are my own personal opinions/content (unless otherwise noted) and do not represent my employer's view in any way.