Problem with Dependency Injection (Prism 4) and DataTemplate that contains toolkit controls

Topics: Prism v4 - Silverlight 4
Dec 8, 2010 at 2:20 PM


I ran into a problem that seems to be happening when I use dependency injection via Prism (version 4)  with a view that contains DataTemplate that has DockPanel inside it (or any control from the toolkit namespace). When the view is instantiated by the container, I get an exception that the namespace that contains the DockPanel does not exist, even though in the designer everything is fine. What makes this even less understood, is that if I add DockPanel to the user control (in addition to the one in the DataTemplate) then everything is fine, both DockPanels are shown.

Here is how the code basically looks:

  •  ·         The namespace used for DockPanel was added by Visual Studio when I dragged it from the toolbox, and is defined like this:


  • ·         In the user control the DataTemplate is defined as follows:


    <DataTemplate x:Key="JobItemDataTemplate">
         <Border BorderBrush="Black" BorderThickness="0,0,0,1">
                      <ColumnDefinition Width="*"/>
                      <ColumnDefinition Width="100"/>
                 <toolkit:DockPanel Grid.Column="0">
                      <TextBlock Text="{Binding Name, Mode=TwoWay}" FontWeight="Bold" toolkit:DockPanel.Dock="Top"/>
                      <TextBlock Text="{Binding Description, Mode=TwoWay}" Height="24" toolkit:DockPanel.Dock="Top"/>



  • ·         Then I have a ListBox in the user control itself that uses the above template:

 <Grid x:Name="LayoutRoot" Background="White">

    <ListBox x:Name="m_jobsListBox" ItemTemplate="{StaticResource JobItemDataTemplate}" 


  • ·         In my ModulInit, I register my user control within a region like this:
m_regionManager.RegisterViewWithRegion( RegionNames.JobsListRegion, () => m_container.Resolve<JobsListView>() );
  • ·         In run time, I get the following exception:
"The type 'DockPanel' was not found because '' is an unknown namespace."
  • ·         If I add the following line after the ListBox, then everything is fine! -
<toolkit:DockPanel Height="100" HorizontalAlignment="Left" Margin="33,188,0,0" Name="dockPanel1" VerticalAlignment="Top" Width="200" Background="#FF00D600" />
  • · The problems happens with any control defined in the toolkit namespace, not just the DockPanel.
  • I tried cleaning the solution, removing the DockPanel and inserting it again (for possible references problem), and it didn't help
  • This also works if I don't use Prism and create the user control without dependency injection (plain silverlight 4 application).
Any help would be welcome.
Dec 9, 2010 at 6:24 PM

Hi Ilan,

You could try adding a reference to the Toolkit assemblies you are using in your Shell project.

Let me know if you keep experiencing this problem after adding the aforementioned reference.

You might also find this thread useful.

I hope you find this helpful.

Guido Leandro Maliandi

Dec 12, 2010 at 7:05 AM

Hi Guido,

Yes, adding the reference to the shell project indeed solved the problem, thanks!

From the link that you sent it seems that if I use control with data template I manually need to add references it uses to the application project. Surprising.

Thank you for the quick response and for resolving this issue for us!