siva
siva

Reputation: 53

System.InvalidOperationException: No XAML was found at the location

I have a wp7 app using the galasoft mvvm light toolkit. It is weird that the url is getting malformed at the time of navigation even though my code is creating the right url for navigation

The uri that is being generated is something like this from the exception

{"No XAML was found at the location '/Views/EditItemGroupid=3.xaml'."}

Any ideas why the url would be like that. Just breaking my head over this.

Thanks

On the xaml side..

<ListBox x:Name="ItemGroupsList" 
         ItemsSource="{Binding ItemGroups}" 
         Height="496" 
         SelectedItem="{Binding SelectedItemGroup, Mode=TwoWay}">
    <Custom:Interaction.Triggers>
        <Custom:EventTrigger EventName="SelectionChanged">
            <GalaSoft_MvvmLight_Command:EventToCommand 
                x:Name="SelectionChangedEvent" 
                Command="{Binding GoToEditItemGroupCommand, Mode=OneWay}" 
                PassEventArgsToCommand="True"/>
        </Custom:EventTrigger>
    </Custom:Interaction.Triggers>

The code on my view model

GoToEditItemGroupCommand = new RelayCommand(() => this.GoToPage(
    "EditItemGroup",
    string.Format("id={0}", SelectedItemGroup != null
        ? SelectedItemGroup.ItemGroupId : 0)
));

protected object GoToPage(string pageName, string queryString)
{
    var msg = new GoToPageMessage()
    {
        PageName = pageName, 
        QueryString =  queryString
    };
    Messenger.Default.Send<GoToPageMessage>(msg); 
    return null;
}

The code in my view code behind in the constructor Messenger.Default.Register(this, (action) => this.ReceiveMessage(action));

The code in the receivemessage method

private object ReceiveMessage(GoToPageMessage action)
{
    StringBuilder sb = new StringBuilder("/Views/");
    sb.Append(action.PageName);
    sb.Append(".xaml");

    if (!string.IsNullOrEmpty(action.QueryString))
    {
        sb.Append("?");
        sb.Append(action.QueryString);
    }

    NavigationService.Navigate(new Uri(sb.ToString(), UriKind.Relative));

    return null;
} 

The GoToPageMessage is defined as

public class GoToPageMessage
{
    public string PageName { get; set; }

    public string QueryString { get; set; }
}

More exception details... sorry this may come out ugly

Upvotes: 2

Views: 3108

Answers (2)

Vijay Singh Rana
Vijay Singh Rana

Reputation: 1090

After upgrading a WP7 app to WP8 (VS 2013 RC), I got this very annoying error when trying to run the app in the emulator. no xaml was found at the location ‘/mainpage.xaml'.

I discovered a one line fix; In the AssemblyInfo.cs file, you have to change the line:

[assembly: NeutralResourcesLanguage("en", UltimateResourceFallbackLocation.Satellite)]

To

[assembly: NeutralResourcesLanguage("en")]

One line fix!. Pity the error message is not helpful at all.

Upvotes: 2

AxelEckenberger
AxelEckenberger

Reputation: 16926

Judging by the rewriting that is done within the Navigate method, I would assume that you use an URL mapper that might cause the problem. To make it work adjust your URI mapping or remove the Mapper.

See here for more information about WP 7 URI mapping.

Upvotes: 0

Related Questions