This project has moved. For the latest updates, please go here.

Binding Views to XAP Files

Mar 6, 2012 at 1:33 PM
Edited Mar 6, 2012 at 1:35 PM

I'm having problems understanding this

I've created a project that need to load view / module upon requested via menu

I then tried to create a simple project to implement this but no success

Here is my code

Container

<Grid x:Name="LayoutRoot" Background="White" d:DataContext="{d:DesignInstance ViewModels:MainViewModel, IsDesignTimeCreatable=True}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" FontSize="36" Text="{Binding Welcome}"/>
        <ContentControl Grid.Row="2" Regions:ExportAsRegion.RegionName="AppRegion" />
        <Button Grid.Row="1" Content="Test" Click="Button_Click" />
    </Grid>

Container Code Behind

 

[ExportAsView(typeof(MainPage), IsShell=true)]
    public partial class MainPage
    {
        [Import]
        public IEventAggregator EventAggregator { get; set; }

        public MainPage()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            EventAggregator.Publish(new ViewNavigationArgs("Dynamic"));
        }

        [Export]
        public ViewXapRoute DynamicRoute
        {
            get { return ViewXapRoute.Create("Dynamic", "EDIT.PatientModule.xap"); }
        }
    }

 

Module Code Behind

 

[ExportAsView("Dynamic")]
    [ExportViewToRegion("Dynamic", "AppRegion")]
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }
    }

 

I'm new to this framework and really interested in this

Hopefully someone can help me and explain how does this work

Coordinator
Mar 6, 2012 at 1:44 PM

Have you looked at the dynamic quick start to compare? There is an example of dynamically loading and you might want to see - I'd also use Fiddler and/or debug to see if it's even attempting to load your XAP file. You can step through the routing to see that it picks up the routed entry and attempts to load the dynamic module. From what I see it looks correct but may be something missing.

Mar 6, 2012 at 2:47 PM

I've been reading the documentation, your blog post and the quickstart as example and it seems similar to my implementation

I'll try  to use fiddler to monitor the loading of xap

I've used debugging but it stops at the EventAggregator

1.Can you explain how it is connected?

2.Does the property "DynamicRoute" plays a part in this?

3.If the Silverlight Application is WCF RIA enabled, does it affect the routing?

Coordinator
Mar 6, 2012 at 2:57 PM

Can you send me a project? I'll be happy to troubleshoot - you can use the contact form for the project to send me a message and I'll reply with my personal email. In general:

1. How what is connected? The XapRoute registers that the view is in a different Xap file, you exported the view itself, so when you raise the navigation event, the Jounce routing component should pick it up, look in the reference table to see the XAP, load the XAP, then attempt to place the view inside the region for you. I'm assuming your main page has the region defined.

2. It plays a part because it informs the navigation system what XAP to load when you request a view that's not in the current XAP

3. It should not.

Mar 7, 2012 at 1:44 PM

Jeremy,

I've monitor my project HTTP Get / Request and it seems that it is trying to get the xap file.

I've also tried creating another project using Jounce 1.0 vs Silverlight 4 but the same error occurs.

I've also tried using Chrome but with no success.