AboKevo
AboKevo

Reputation: 115

making different views in silverlight

I have a silverlight application and a website hosting it,i have three links in the asp webpage i want on each link to show a different silverlight applicaion or different silverlight view .In windows forms we simply make a new form , but in Silverlight how its done? by making new project and re-hosting the XAP file or add another Page.Xaml file.?

i did like this :

<Application.Resources>
    <ResourceDictionary x:Key="AppResource">
        <navigationCore:UriMapper x:Key="UriMapper">
            <navigationCore:UriMapping Uri="page1" MappedUri="AddRoute.xaml"/>
        </navigationCore:UriMapper>
    </ResourceDictionary>
</Application.Resources>

and in the asp like this :

<a href="Page1.aspx">Page1</a>

Upvotes: 0

Views: 357

Answers (1)

tsiorn
tsiorn

Reputation: 2236

would create one silverlight application (XAP file) and create 3 different views. You could add a UriMapper to your silverlight application and then have your html links just point to the silverlight pages. Below is how you could setup this mapper in your App.xaml

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"    
             xmlns:navigationCore="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
             mc:Ignorable="d">

    <Application.Resources>
        <ResourceDictionary x:Key="AppResources">

            <!-- Uri Mapper -->
            <navigationCore:UriMapper x:Key="UriMapper">
                <navigationCore:UriMapping Uri="Page1" MappedUri="/View/Page1.xaml" />
                <navigationCore:UriMapping Uri="Page2" MappedUri="/View/Page2.xaml" />
                <navigationCore:UriMapping Uri="Page3" MappedUri="/View/Page3.xaml" />
            </navigationCore:UriMapper>


        </ResourceDictionary>

    </Application.Resources>
</Application>

Now you could simply setup your html links as:

<a href="http://site.com/#Page1">Page 1</a>
<a href="http://site.com/#Page2">Page 2</a>
<a href="http://site.com/#Page3">Page 3</a>

In the end, having one silverlight xap will create a better user experience and avoid having to constantly spin up each app if they were separate

Edit:

Note: The MappedUri above is a path WITHIN your silverlight application. So if your silverlight application is placed on Page1.aspx page, then the URL you need is something like:

<a href="Page1.aspx#page1>Page 1</a>

"page1" is definied in your app.xaml

Upvotes: 2

Related Questions