WP8 - views in subfolders

Topics: Conventions, Getting Started
Feb 18, 2013 at 1:43 PM
Edited Feb 19, 2013 at 8:45 AM
I’m starting playing with Caliburn.Micro on WP8. I have recompiled sample from WP 7.1 and it works fine but next step was organizing directory tree (Views goes to Views sub dictionary and ViewModels to ViewModels sub dictionary). I have also modify WMAppManifest.xml to load main view from proper location and application runs but navigation to another view is not working. I have an error:

No XAML was found at the location '/PivotPage.xaml'

when using this syntax:

navigationService.UriFor<PivotPageViewModel>()

it works with this

navigationService.Navigate(new Uri("/Views/PivotPage.xaml?NumberOfTabs=5", UriKind.RelativeOrAbsolute));

but I would like to use first syntax

How to instruct Caliburn to use ‘Views/PivotPage.xaml’ location?
Feb 21, 2013 at 10:00 AM
After some changes in namespaces – unifying folder structure with namespace, CM translates uri to view in this way:

[Root namespace]/Views/PivotPage.xaml

I don’t know if this a bug in CM or I’m missing something in convention somewhere in code. For now I changed some code in CM to fix this
public static Func<Type, Type, string> DeterminePackUriFromType = (viewModelType, viewType) => {
            
            var assemblyName = viewType.Assembly.GetAssemblyName();

            var application_type = viewType.Assembly.GetTypes().Where(t => t.Name == "App").FirstOrDefault();
            string view_type_uri = viewType.FullName;
            
            if(application_type != null)
            {
                var len = application_type.Namespace.Length;
                view_type_uri = view_type_uri.Substring(len, view_type_uri.Length - len);
            }

            var uri = view_type_uri.Replace(assemblyName, string.Empty).Replace(".", "/") + ".xaml";

            if(!Application.Current.GetType().Assembly.GetAssemblyName().Equals(assemblyName)) {
                return "/" + assemblyName + ";component" + uri;
            }

            return uri;
        };