Having Trouble Getting Started on Windows Phone 8

Topics: Conventions, Getting Started
Apr 23, 2013 at 4:37 PM
Edited Apr 23, 2013 at 6:52 PM
My question has been answered. Thanks McDonnellDean


I'm new to Caliburn and having difficulty getting this started.

I have an InfoTileViewModel.cs (in the ViewModels directory and namespace), an InfoTile.xaml (in the Views directory and Namespace), I'm pretty sure I've built the Bootstrapper correctly and App.xaml/.cs files correctly built. I have built a sample app that works and the only obvious difference is the directory of project/project name is not the same as the main namespace (I have a WP8 and WP7 version of the app, so both projects share the same namespace but obviously have different project names). Here's the relevant code, and I'll include a screenshot of my Solution structure.

In the code below I have the ViewModel set to display a Messagebox (I'm trying to work off this blog post: http://wp.qmatteoq.com/first-steps-with-caliburn-micro-in-windows-phone-8-the-first-project/ ), when I start debugging the app, I don't receive any errors, everything loads properly, but the Messagebox does not fire.

Does anything jump out to anyone as something that's obviously wrong? Because I'm not seeing anything.

ViewModels/InfoTileViewModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace Formstack.ViewModels
{
    public class InfoTileViewModel
    {
        public InfoTileViewModel()
        {
            MessageBox.Show("HOWDY");
        }
    }
}
Views/InfoTile.xaml
<phone:PhoneApplicationPage
    x:Class="Formstack.Views.InfoTile"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>
ProjectRoot/Bootstrapper.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Caliburn.Micro;
using Formstack.ViewModels;

namespace Formstack
{
    public class Bootstrapper : PhoneBootstrapper
    {
        PhoneContainer container;

        protected override void Configure()
        {
            container = new PhoneContainer(RootFrame);

            container.RegisterPhoneServices();
            container.PerRequest<InfoTileViewModel>();

            AddCustomConventions();
        }

        static void AddCustomConventions()
        {
            //ellided  
        }

        protected override object GetInstance(Type service, string key)
        {
            return container.GetInstance(service, key);
        }

        protected override IEnumerable<object> GetAllInstances(Type service)
        {
            return container.GetAllInstances(service);
        }

        protected override void BuildUp(object instance)
        {
            container.BuildUp(instance);
        }
    }
}
ProjectRoot/App.xaml
<Application
    x:Class="Formstack.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:cBoot="clr-namespace:Formstack">

    <!--Application Resources-->
    <Application.Resources>
        <cBoot:Bootstrapper x:Key="bootstrapper" />
    </Application.Resources>

</Application>
ProjectRoot/App.xaml.cs
using System;
using System.Diagnostics;
using System.Resources;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Formstack.Resources;
using Formstack.ViewModels;
using Formstack.Models;
using Formstack.Utilities;
using System.Net;

namespace Formstack
{
    public partial class App : Application
    {
        public static User currentUser = null;
        public static FormstackApiHandler apiHandler = null;

        /// <summary>
        /// Provides easy access to the root frame of the Phone Application.
        /// </summary>
        /// <returns>The root frame of the Phone Application.</returns>
        public static PhoneApplicationFrame RootFrame { get; private set; }
 
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {

            // Standard XAML initialization
            InitializeComponent();

            // Show graphics profiling information while debugging.
            if (Debugger.IsAttached)
            {
                // Display the current frame rate counters.
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Prevent the screen from turning off while under the debugger by disabling
                // the application's idle detection.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }
        }

    }
}
Screenshot of my WMAppManifest and Solution Structure http://cl.ly/image/0P1n1m1D0f13/wmappmanandstructure.png
Screenshot of my WMAppManifest and Solution Structure
Apr 23, 2013 at 4:56 PM
Hi FormstackDev,

Before we go any further could you tell me what happens when you run? Or to be more precise, what is the issue you are having?
Apr 23, 2013 at 5:10 PM
Edited Apr 23, 2013 at 5:15 PM
I run, and the MessageBox does not fire. No errors, just nothing that would indicate that the ViewModel and View are linked occurs. I've read some other posts that indicates that the Namespace not matching the Project Name could be the issue.

Edit: I just renamed all of the namespaces in those files to XStack_WP8, and it's still not doing anything.
Apr 23, 2013 at 6:38 PM
Edited Apr 23, 2013 at 6:39 PM
I didn't see an issue with your namespaces. I do notice however that your View is not called InfoTileView. This is what it looks for by convention.

This explains how the conventions work: https://caliburnmicro.codeplex.com/wikipage?title=View%2fViewModel%20Naming%20Conventions&referringTitle=Documentation
Apr 23, 2013 at 6:52 PM
...and now I feel like an idiot. I was positive I had tried that naming convention, but as soon as I changed the names in the View it worked instantly. Thanks!
Apr 23, 2013 at 7:41 PM
No panic,

I still do it every so often! You learn after a while to check your conventions first.