No Free Time

Because my therapist says I need to let things out

Archive for March 30th, 2008

Silverlight 2: How to put a user control inside a DataTemplate

Posted by andrewmyhre on March 30, 2008

Note: this post is quite old and probably doesn’t apply to the latest Silverlight 2 release.

I have a Silverlight user control with the following XAML:

<UserControl x:Class=”Continuator.SimpleControl”
xmlns=”http://schemas.microsoft.com/client/2007″
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
Width=”400″ Height=”300″>
<Grid x:Name=”LayoutRoot” Background=”White”>
<TextBlock Text=”hello” />
</Grid></UserControl>I want to use it in a ListBox/StackPanel data template. To do so I first add a reference from my Page.xaml:

<UserControl x:Class=”Continuator.Page”
xmlns=http://schemas.microsoft.com/client/2007
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
xmlns:c=”clr-namespace:Continuator;assembly=Continuator”
xmlns:d=http://schemas.microsoft.com/expression/blend/2008
xmlns
:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″ mc:Ignorable=”d”
Width=”800″ Height=”600″>

(My project namespace is called Continuator). The specifying the assembly is crucial – this won’t work without it and in my case actually caused a bad memory leak. Now add your ListBox to the page, with the control specified in the data template:

<ListBox x:Name=”ProjectsList”>
<ListBox.ItemTemplate>
<DataTemplate>
<c:SimpleControl />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
If you’ve tried this and have had problems, check that you’re including the assembly in the namespace reference. I found this tip in this thread.

Posted in silverlight | Tagged: | 1 Comment »

No profile

Posted by andrewmyhre on March 30, 2008

I was just reading Tim Sneath’s ‘live blog’ of the Ballmer/Kawasaki keynote at Mix, and noticed he blogged my question to Ballmer:

“1:46pm – Attendee: .NET is great and there’s been lots of innovation on this side of the developer platform; why did IE get left out for so long? Steve: partly because Internet Explorer was shipped as part of the operating system and there was a long gap between Windows XP and Windows Vista. You won’t see that kind of gap again – we now understand how to get things decoupled sufficiently to develop innovations separately from the OS and then bring them back later.”

I have to say, out of all the cool things that I was lucky enough to be a part of at Mix, actually talking to the man himself is what stands out in my memory. I’m a guy with absolutely no profile and yet I get the chance to ask him a somewhat impertinent question, and he took me seriously and gave his best answer. To me that’s just cool, and one of the reasons why I like the .Net community so much.

If you haven’t seen it, you can watch the keynote here. I’m at about 39 minutes in :) .

Posted in .net, mix08 | Tagged: , | Leave a Comment »