Silverlight CustomControls and Blend 2

  • nederlands
26 12 2007

Most of you would have probably stopped developing in silverlight 1.1 2.0 after seeing how custom controls worked in blend 2 (they do nothing). But for those of you who persevered some tips to help you on your way.

Xaml

The current control model is absolutely unfinished. One of the firts thins you have to do is change the way a CustomControl is loaded, and map the controls in your xaml to your code.

System.IO.Stream s =
  this.GetType().Assembly.GetManifestResourceStream(“UserControl1.xaml”);
FrameworkElement _actualControl = this.InitializeFromXaml(
  new System.IO.StreamReader(s).ReadToEnd()
);
_actualControl.FindName(“Button”);Namespaces

Blend 2 doesn’t understand it when you put namespaces in your customcontrol xaml, it does work in the xmlns decleration but not in the actual xaml control.

Wrong:
<CustomControls: Buttons.RoundButton …..=“” /> and
<CustomControls.Buttons: RoundButton …..=“” />

Right:
<CustomControls:RoundButton …..=“” />

Visual Containers

Because custom controls do not show in blend 2, making layouts is a very dificult story. One solution is to create rectangles for every custom control and name them the same except for a temp_ prefix.

Then in the onloaded event of your page, cycle trough your object tree and place the custom controls over the rectangles and remove them.

More to come.

Robertjan Tuit


Actions

Informations

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>