Even a chimp can write code

Saturday, August 11, 2007

Silverlight 1.1 controls from ComponentOne

ComponentOne Labs features a suite of over 30 UI controls and components for Silverlight 1.1. This is an impressive list covering the gamut with buttons, text controls, lists, date pickers and layout containers. Apparently charting controls and grid are in the works. You can play with these controls on their slick gallery. I'm very impressed.

My team shipped a set of sample UI controls with the Silverlight 1.1 Alpha SDK building on the platform's basic foundations for control extensibility. I've been pleasantly surprised by the the sorts of things the community has done with what can only be kindly referred to as rudimentary support in the platform. As Silverlight 1.1 evolves, you will see the platform provide a lot of the building blocks such as robust keyboard/input support, a layout system, basic UI controls and more. The possibilities are endless. Of course, there's still a lot to get done. If you've read this far, you probably care. Please tell us about your experiences building RIAs using Silverlight and what you'd like to see in the platform and the framework.

Labels: , ,

Email this | Bookmark this

Thursday, May 17, 2007

Namescopes in Silverlight

When you start naming things, you quickly realize that you need a method to disambiguate or resolve conflicts between names. When your sister cried out "Mom! Pete flushed the goldfish down the toilet!", your mom knew the "Pete" your sis was referring to was you, not the kid down the street. That's because she used an implicit name scope to infer.

What is a name scope?
Nick Kramer describes a name scope or namescope thusly:
"In almost all programming languages, names are not globally unique, they are unique only relative to other names in the same name scope. In C++ and C#, a name scope is roughly what goes between curly braces -- { }. And in C++ and C#, namescopes nest -- if the compiler can't find the name in the nearest namescope { }, it will look in the containing namescope.

Xaml names have many of the same issues. In <Button Name="foo">, foo is not unique to the whole program, there could be other xaml files with the same name. And you can instantiate that xaml file multiple times (e.g., multiple windows). "


Nick goes on to explain the role namescopes play in WPF. They kinda play a similar role in Silverlight.

Okay so we now know that a namescope is a logical grouping of named elements. Further, the "root" or ownership of a namescope is tied to a specific element and all of its named children fall into that namescope unless a child defines another namescope. This element is considered having the ownership of the namescope.

When do I care?
A namescope is typically created when the root visual is set. Well, in Silverlight there's a couple ways you, the app developer, can create elements in a separate namescope. One way is through a createFromXaml call in Javascript where you set the last parameter to true. The other is when you instantiate a Silverlight 1.1 Alpha control (see the SDK). In the latter case, the ControlBase class constructor makes a call to InitializeFromXaml in System.Windows.Controls.Control - which in a way is the managed equivalent of making a createFromXaml(xaml, createNamescope) call. You can use that approach for your custom controls.

Update: And oh, you also care when you do a FindName(). That method only walks the tree in the namescope of the element on which FindName was called. For instance, of you do rootCanvas.FindName("someElementName") you're searching for "someElementName" in the namescope of the rootCanvas element. Another element with the same name but different namescope is invisible at this time.

What types of namescopes exist?

The namescope created with the root visual is called the default namescope. When you call createFromXaml and tell it to create a namescope this is called a private namescope. If you call createFromXaml and do not create a namescope a temporary namescope is created

All elements content created in the visual tree will reside inside the namescope. Names defined in the namescope will not conflict with other names outside of the namescope.
Silverlight Namescopes
Default namescope
A default namescope is automatically created when the root visual is created. The default namescope can be replaced by resetting the main visual tree.

Private namescope
A private namescope is the permanent name scoping that is created. A private namescope has the restrictions mentioned earlier in that it cannot be dissolved – it is always associated with the element that owns the private namescope. Named/un-named elements can be added/remove from the private namescope though.

Temporary Namescope
A temporary namescope is created any time you call createFromXaml and have an element tree fragment not associated with the main tree. A temporary namescope is different from a private namescope in that when you add the element tree fragment to another tree the temporary namescope is dissolved. This "addition" can be by using a collection's Add method or by setting a property such as a Rectangle's Fill.

Labels: , , , ,

Email this | Bookmark this

A Layout System and Containers for Silverlight 1.1 Alpha

Dave Relyea's first blog post showcases some work he'd been recently doing to build a layout system, several layout containers and some layout-aware controls -- all in user code. Ooh, but that's not all. Dave cranked up a pretty cool TextBox control as well. See Silverlight 1.1 Alpha Layout System and Controls Framework.

You can use this until the Silverlight 1.1 platform natively supports layout and editing (which is... soon).

Labels: , ,

Email this | Bookmark this

Thursday, May 03, 2007

Silverlight UI Controls

Update [Apr 2009]: The post below is now obsolete. There is now a great ecosystem of UI controls for Silverlight. You can start with the Silverlight Toolkit, a Microsoft provided collection of Silverlight controls, components and utilities made available for your development with a permissive license (MSPL). Besides, there are excellent controls from ComponentOne, Telerik, Infragistics etc. There's also some good documentation on Silverlight Controls on MSDN.

-----

If you've played with Microsoft Silverlight 1.0 Beta or 1.1 Alpha bits, you've no doubt noticed that while there's Canvas, TextBlock and other such controls, there is no Button or ListBox or even layout elements like StackPanel or Grid. Rest assured, your UI development needs are always on our mind.

If you download the Silverlight 1.1 Alpha SDK, you'll see a UI controls package in there. You didn't think we'd leave you in the lurch, did you? Although it is very easy to whip up a Button control with XAML and some code in Silverlight, that detracts from your app building. To address this, we've released a modest set of controls in the Silverlight UI Controls package. These include:

  • Button
  • ScrollBar
  • ScrollViewer
  • Slider
  • ListBox

Also included are a couple primitives like RepeatButton, Thumb and GripThumb.

All of the controls in that package are managed code controls i.e. they rely on Silverlight 1.1 Alpha and the CLR and Silverlight framework in it.

These controls currently sport the Silverlight "Dawn" look and feel. We're releasing source code for these controls so you can modify and customize them as appropriate. There is a readme file with additional information and the code is peppered with comments, all which the agile diehards are free to ignore, 'cause the code is the documentation. The control behavior is in C# code-behind files, while the control templates, i.e. the visual aspects governing look and feel, are in XAML markup files. Another example of separating UI from behavior, as architecture astronauts have been telling us since the dawn of time.

Silverlight 1.1 Alpha SDK - UI Controls

Controls such as ScrollBar, ScrollViewer, ListBox and Slider are composed of other controls. We picked this mix because it accentuates the diversity of the control set and allows you - the designer or developer - to look at the source code and understand the Silverlight framework, the inter-dependencies between controls, and not to mention, the quirks in the control set arising from some features being absent in the 1.1 Alpha.

Please use these controls in your applications targeting Silverlight 1.1 Alpha. In fact, it should be pretty simple to take the XAML pieces, tie in some JavaScript and have all of this run on 1.0 Beta. But I'll leave that to the community.

As always, direct comments and bug reports on the UI controls to the Silverlight Forums. If you have questions about the control roadmap or other considerations made while developing this set, drop me a line here.

Labels: , ,

Email this | Bookmark this