European Silverlight 4 & Silverlight 5 Hosting BLOG

BLOG about Silverlight 5 Hosting and Its Techologies - Dedicated to European Windows Hosting Customer

Silverlight Hosting - HostForLIFE.eu :: InitParams in Silverlight

clock November 20, 2026 13:05 by author Peter

We can send the key value pair from the aspx page itself if you are creating a Silverlight application and you need to enter certain parameters within, like a key and value pair. In Silverlight, we'll show how we can accomplish this.

Start a Silverlight Project

Adding parameters
Open the "InitializingParametersTestPage.aspx" and find the tagtag <asp:Silverlight add an attribute InitParameters
Enter the following code to the tag
    InitParameters="Key1=Value1,Key2=Value2"

Defining the Parameters
In App.xaml.cs add an object of IDictionary<string,string> as follows
    public IDictionary<string, string> AppParams;
    In Application_Startup event initialize the parameters as follows
    private void Application_Startup(object sender, StartupEventArgs e)
    {
    AppParams = e.InitParams;
    this.RootVisual = new Page();
    }


Using Parameters
In Page.xaml add ListBoxes to show the parameter values

Xaml Code
    <UserControl x:Class="InitializingParameters.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="#FFB7C2E5">
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="0.472*"/>
    <ColumnDefinition Width="0.025*"/>
    <ColumnDefinition Width="0.502*"/>
    </Grid.ColumnDefinitions>
    <ListBox x:Name="myKeysList"/>
    <ListBox x:Name="myValuesList" Grid.Column="2"/>
    </Grid>
    </UserControl>

In code behind of the Page.xaml.cs add the following code to bind the parameters
    namespace InitializingParameters
    {
    public partial class Page : UserControl
    {
    public Page()
    {
    InitializeComponent();
    App myApp = App.Current as App;
    foreach (string item in myApp.AppParams.Keys)
    {
    myKeysList.Items.Add(item);
    }
    foreach (string item1 in myApp.AppParams.Values)
    {
    myValuesList.Items.Add(item1);
    }
    }
    }
    }


Runnning the Application
When you run the application the list will carry the key and value pairs.

Hope you like the article, Enjoy Coding. 

HostForLIFE.eu Silverlight 5 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



Silverlight Hosting - HostForLIFE.eu :: URI Mappings in Silverlight Navigation Framework

clock November 9, 2026 12:17 by author Peter

Navigation Framework comes with Silverlight 3 RIA Services. Using this framework we can easily navigate between User Controls in a Silverlight Application. We can enable the Browser History capabilities and URI mappings can also be done.

To start with, we will build a simple Silverlight Application which will be easy to catch up.

Create Silverlight Navigation Application

Create a Navigation Application and name it NavigationFrameworkSample. The following screenshots will guide you through the process.

Creating a Silverlight Navigation Application

Enabling the RIA Features by Linking the web page


Solution explorer
Here MainPage.xaml will work as our master page, which will carry the common elements for the whole projects. Now we will redesign the template to our simple use. It will look like the following. Using Blend 3 I have tried to change the template a bit; you can explore your own creativity.

Changed MainPage.xaml in Blend 3
Xaml Code
    <UserControl x:Class="NavigationFrameworkSample.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="LightBlue">
    <Grid.RowDefinitions>
    <RowDefinition Height="0.107*"/>
    <RowDefinition Height="0.893*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="0.26*"/>
    <ColumnDefinition Width="0.74*"/>
    </Grid.ColumnDefinitions>
    <Border Grid.Row="1" Style="{StaticResource FrameInnerBorderStyle}">
    <StackPanel >
    <Button Click="NavButton_Click" Tag="/Views/HomePage.xaml" Content="Home"
    Style="{StaticResource PageLinkStyle}"/>
    <Button Click="NavButton_Click" Tag="/Views/AboutPage.xaml" Content="About"
    Style="{StaticResource PageLinkStyle}"/>
    </StackPanel>
    </Border>
    <Border Grid.Column="1" Grid.Row="1" BorderBrush="#FF000000" Style="{StaticResource FrameContainerStyle}" Margin="0,0,0,-4">
    <navigation:Frame x:Name="Frame" Source="/Views/HomePage.xaml"
    HorizontalContentAlignment="Stretch"
    VerticalContentAlignment="Stretch"
    Padding="15,10,15,10"
    Background="White"/>
    </Border>
    <TextBlock Grid.Column="1" FontSize="22" VerticalAlignment="Center" HorizontalAlignment="Center" Text="Navigation Framework" TextWrapping="Wrap"/>
    </Grid>
    </UserControl>


Navigation Page
Navigation Framework has its own Page that is called navigation Page. Which we will see further. Navigation Framework's Views Folder consists of the Xaml Pages that are related to the project. In this sample application we have two Xaml Pages, Home.xaml and About.Xaml.

Xaml Code for Home Page
    <navigation:Page x:Class="NavigationFrameworkSample.HomePage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    Title="HomePage ">
    <Grid x:Name="LayoutRoot" Background="White">
    <StackPanel>
    <TextBlock Text="Home" FontSize="20"/>
    <StackPanel>
    <TextBlock Text="Navigation Framework in Silverlight 3" />
    </StackPanel>
    </StackPanel>
    </Grid>
    </navigation:Page>


Xaml Code for About Page
    <navigation:Page x:Class="NavigationFrameworkSample.AboutPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    Title="AboutPage ">
    <Grid x:Name="LayoutRoot" Background="White">
    <StackPanel>
    <TextBlock Text="About" FontSize="20"/>
    <TextBlock Text="Navigation Framework is all about Navigating between User Controls"/>
    </StackPanel>
    </Grid>
    </navigation:Page>


As soon as we create the Navigation Application, System.Windows.Controls.Navigation.DLL is added to the project's reference.
In Navigation framework we have a control called Frame, which can load a Page into this. It has the same concept as Frame in ASP.NET.

To navigate through the pages we will use the following default logic of the framework.
    private void NavButton_Click(object sender, RoutedEventArgs e)
    {
    Button navigationButton = sender as Button;
    String goToPage = navigationButton.Tag.ToString();
    this.Frame.Navigate(new Uri(goToPage, UriKind.Relative));
    }


URI Mapping
This concept is new in Silverlight 3 Navigation Framework. Using this concept we can hide our Xaml page's location and we can achieve security.
To achieve the above said, we need to do a trick in our App.xaml. We need to add the System.Windows.Controls.Navigation.dll to the xaml and change as follows: Change the default namespace.

Before
xmlns:navigationCore="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"

After
xmlns:navigationCore="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"

Now we are enabled to write the URI Mappings. Write the following as per your requirement.
    <navigationCore:UriMapper x:Key="uriMapper">
    <navigationCore:UriMapping Uri="Home" MappedUri="/Views/HomePage.xaml"/>
    <navigationCore:UriMapping Uri="About" MappedUri="/Views/AboutPage.xaml"/>
    </navigationCore:UriMapper>


Change the Following tag in Button
    <Button Click="NavButton_Click" Tag="Home" Content="Home" Style="{StaticResource PageLinkStyle}"/>
    <Button Click="NavButton_Click" Tag="About" Content="About" Style="{StaticResource PageLinkStyle}"/>


Now we can change the path to our Uri anywhere in the project, like we used it in our startup page in MainPage.xaml. We can now change the source attribute of the Frame.
    Source="Home"

Now we are ready to test our Sample and using this framework we enabled our browser history capability by default, that means now we can do Back and Forward for our required destination pages. The following screenshots will guide you through.

Running the Application

Typing the URI after # and getting the page


Browser Histories in IE. 

HostForLIFE.eu Silverlight 5 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



About HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.


Tag cloud

Sign in