Jan 7 2010

Loading XAML at runtime when using external assemblies in Silverlight

Category: Silverlight | Telerik | Telerik ControlsBil@l @ 20:20

In an application I am working on, there is a need to load XAML dynamically from the server to populate a Telerik RadRibbonBar control. The XAML to be loaded is something similar to this:

<StackPanel xmlns:telerikRibbonBar="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.RibbonBar"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:cmd="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation">
    <telerikRibbonBar:RadRibbonBar x:Name="rbnBar"
                                   ApplicationName="VBC Office Tool"
                                   Margin="0"
                                   ApplicationButtonImageSource="../AppIcon.png">
        <telerikRibbonBar:RadRibbonTab Header="VBC">
            <telerikRibbonBar:RadRibbonGroup Header="Clipboard">
                <StackPanel Orientation="Horizontal">
                    <telerikRibbonBar:RadRibbonButton x:Name="btn1"
                                                      CollapseToSmall="Never"
                                                      Size="Large"
                                                      Tag="Module 1"
                                                      cmd:Click.Command="{Binding Path=RibbonCommand}"
                                                      cmd:Click.CommandParameter="{Binding Path=Tag, RelativeSource={RelativeSource Self}}"
                                                      Text="Paste">
                        <telerikRibbonBar:RadRibbonButton.Content>
                            <Image Source="../paste.png" />
                        </telerikRibbonBar:RadRibbonButton.Content>
                    </telerikRibbonBar:RadRibbonButton>
                    <telerikRibbonBar:RadRibbonButton x:Name="btn2"
                                                      HorizontalContentAlignment="Center"
                                                      CollapseToSmall="Never"
                                                      Size="Large"
                                                      Tag="Module 2"
                                                      cmd:Click.Command="{Binding Path=RibbonCommand}"
                                                      cmd:Click.CommandParameter="{Binding Path=Tag, RelativeSource={RelativeSource Self}}"
                                                      Text="Create Document">
                        <telerikRibbonBar:RadRibbonButton.Content>
                            <Image Source="../save.png" />
                        </telerikRibbonBar:RadRibbonButton.Content>
                    </telerikRibbonBar:RadRibbonButton>
                </StackPanel>
            </telerikRibbonBar:RadRibbonGroup>
        </telerikRibbonBar:RadRibbonTab>
        <telerikRibbonBar:RadRibbonTab Header="iRisk" />
    </telerikRibbonBar:RadRibbonBar>
</StackPanel>

 

At the client-side, I am adding the XAML into a ContentControl as follows:

System.Windows.Resources.StreamResourceInfo streamInfo =
    System.Windows.Application.GetResourceStream(new Uri("ContextMenuModule;component/View/RibbonBar.xaml", UriKind.Relative));
if ((streamInfo != null) && (streamInfo.Stream != null))
{
    using (System.IO.StreamReader reader = new System.IO.StreamReader(streamInfo.Stream))
    {
        UIElement uribbon = (UIElement)XamlReader.Load(reader.ReadToEnd());
        this.ribbon.Content = uribbon;
    }
}

On the XamlReader.Load() method, I was getting the following exception:

AG_E_PARSER_BAD_TYPE 

Before I give the solution that I found on a forums’ blog post (http://forums.silverlight.net/forums/t/44877.aspx), let me explain to you the environment where the above code is executing.

It is a Silverlight-Prism application where I have the following structure:

  1. Shell app
  2. Module app

 

The above code is executing inside the Module app and proper references are added to all Telerik assemblies.

Seems that in Silverlight, when loading XAML dynamically in a class library (A) or Silverlight application (B), and then that app or class library is used by another class library (C) or Silverlight app (D), then all external assemblies that were used by (A) and (B) should also be added to (C) and (D).

Therefore, all Telerik assemblies used by Module app should also be added to the Shell application.

 

Hope this helps,
Regards

Tags: , ,

Sep 10 2009

TFS Work Item Manager &amp; TFS Project Dashboard Beta

Category: TelerikBil@l @ 16:09

Telerik release two new FREE products:

  1. TFS Work Item Manager
  2. TGS Project Dashboard

Get more details from here: TFS Work Item Manager and TFS Project Dashboard 

 

Regards

 

 

Tags: