WP7 Example

Sep 15, 2011 at 9:47 AM

Hello, I found the article you published on CodeProject at the following address:

http://www.codeproject.com/KB/windows-phone-7/Catel_Part6.aspx

I followed the instructions (installing Catel.WP7 version 2.1 via Nuget) but i get the following compile error:

Error 1 The property 'ViewModel' does not exist on the type 'MainPageIntermediate' in the XML namespace 'http://catel.codeplex.com'. D:\IT\Articles\BingMapsDemo\src\Catel.Examples.WP7.BingMaps\Views\MainPage.xaml 15 8 Catel.Examples.WP7.BingMaps

Where am I wrong?

Thanks for your help.

Salvatore

 

 

Coordinator
Sep 15, 2011 at 10:08 AM

Strange, I downloaded the example demo (originally created with Catel 1.4), and had to change the following subjects:

  • IoC has changed, now need ServiceLocator.RegisterType in MainPageViewModel
  • EventToCommand has changed in namespace, must be updated in MainPage.xaml

After that, it worked like a charm!

Can you show your code-behind of the MainPage.xaml (thus MainPage.xaml.cs)?

Sep 15, 2011 at 10:10 AM
GeertvanHorrik wrote:

Strange, I downloaded the example demo (originally created with Catel 1.4), and had to change the following subjects:

  • IoC has changed, now need ServiceLocator.RegisterType in MainPageViewModel
  • EventToCommand has changed in namespace, must be updated in MainPage.xaml

After that, it worked like a charm!

Can you show your code-behind of the MainPage.xaml (thus MainPage.xaml.cs)?

Hi, here is the code:

 

namespace Catel.Examples.WP7.BingMaps.Views
{
    using Catel.Phone.Controls;
 
    using ViewModels;
 
    /// <summary>
    /// Interaction logic for MainPage.xaml.
    /// </summary>
    public partial class MainPage : MainPageIntermediate
    {
        public MainPage()
        {
            InitializeComponent();
        }
    }
 
    /// <summary>
    /// Intermediate class since WP7 doesn't support generic base classes.
    /// </summary>
    public class MainPageIntermediate : PhoneApplicationPage<MainPageViewModel>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="MainPageIntermediate"/> class.
        /// </summary>
        /// <remarks>
        /// This constructor can only be used for design-time support. An exception will be thrown when it is used
        /// outside a designer.
        /// </remarks>
        public MainPageIntermediate()
        {
        }
    }
}
Coordinator
Sep 15, 2011 at 10:13 AM

Looks great, can you show the xaml itself as well?

Sep 15, 2011 at 10:16 AM
Edited Sep 15, 2011 at 10:19 AM

Sure!

 

<Views:MainPageIntermediate x:Class="Catel.Examples.WP7.BingMaps.Views.MainPage"
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
							xmlns:catel="http://catel.codeplex.com"
                            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"
                            xmlns:Views="clr-namespace:Catel.Examples.WP7.BingMaps.Views"
                            mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
                            FontFamily="{StaticResource PhoneFontFamilyNormal}"
                            FontSize="{StaticResource PhoneFontSizeNormal}"
                            Foreground="{StaticResource PhoneForegroundBrush}"
                            SupportedOrientations="Portrait" Orientation="Portrait"
                            shell:SystemTray.IsVisible="True"
							catel:Designer.ViewModel="Catel.Examples.WP7.BingMaps.ViewModels.DesignMainPageViewModel, Catel.Examples.WP7.BingMaps">	
	
    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
 
        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="{Binding Title}" 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">
 
			<!-- Use this grid to place your real content -->
			
			<ListBox ItemsSource="{Binding Items}">
			    <ListBox.ItemTemplate>
				    <DataTemplate>
					    <TextBlock Text="{Binding Name}" />
					</DataTemplate>
				</ListBox.ItemTemplate>
			</ListBox>
	
        </Grid>
 
		<!--Sample code showing usage of the bindable ApplicationBar of the Phone7.Fx.Preview assembly-->
        <!--<Preview:BindableApplicationBar Grid.Row="2" IsVisible="True" IsMenuEnabled="False">
            <Preview:BindableApplicationBarIconButton Command="{Binding Home}" IconUri="/Resources/Images/home.png" Text="Home" />
            <Preview:BindableApplicationBarIconButton Command="{Binding Add}" IconUri="/Resources/Images/add.png" Text="Add" />
            <Preview:BindableApplicationBarIconButton Command="{Binding Edit}" IconUri="/Resources/Images/edit.png" Text="Edit" />
            <Preview:BindableApplicationBarIconButton Command="{Binding Delete}" IconUri="/Resources/Images/delete.png" Text="Delete" />
        </Preview:BindableApplicationBar>-->
    </Grid>	
 

</Views:MainPageIntermediate>
Coordinator
Sep 15, 2011 at 10:20 AM

Ah, now I see. The Designer.ViewModel is obsolete (declared obsolete in 2.0, removed in 2.1). There are 2 options to solve this problem:

1) Delete the line catel:Desiger.ViewModel=..., but then you will loose design time support

2) Use this technique (which is now recommended)

Sep 15, 2011 at 10:29 AM

It works with solution 1)  but now I'll try to use the number 2)!

Thanks for the interesting project!

Salvatore