Issue when passing enum using navigation service (WP7)

Topics: Bugs
May 9, 2011 at 9:00 PM

Hi, maybe it's just my fault but I'm experiencing the following issue using CM with WP7: when passing a parameter to another page via query string using the navigation service, if the parameter is an enum the target VM always receives the default (0) value instead of the parameter's value.

You can repro the issue as follows:

  1. create a new CM WP7 application
  2. in the main viewmodel add:
    public class MainPageViewModel : Screen
    {
      readonly INavigationService _navigation;
      public MainPageViewModel(INavigationService navigation)
      {
        _navigation = navigation;
      }
      public void GotoColorChooser()
      {
        _navigation.Navigate(new Uri("/Views/ColorChooserView.xaml?Color=" + TheColor.Green,
          UriKind.RelativeOrAbsolute));
      }
    }
    
    public enum TheColor
    {
      Red, Green, Blue
    }
    
  3. in its view just add a button like:
      <Button Content="Color chooser"
          Name="GotoColorChooser"/>
    
  4. add under folder ViewModels a VM named ColorChooseViewModel:
    public class ColorChooserViewModel : Screen
    {
      private readonly INavigationService _navigation;
      private TheColor _color;
    
      public TheColor ChosenColor
      {
        get { return _color; }
        set
        {
          _color = value;
          NotifyOfPropertyChange(() => ChosenColor);
        }
      }
    
      public ColorChooserViewModel(INavigationService navigation)
      {
        _navigation = navigation;
      }
    }
    
  5. add its view under folder Views as a standard WP7 portrait page with content:
    <TextBlock Name="ChosenColor" />
    
  6. run the code and click the button. You navigate to the color chooser page, but the chosen color property is set to red instead of green.

Should you require it I can post this sample repro code. Could anyone help?

Coordinator
May 9, 2011 at 9:07 PM
Edited May 9, 2011 at 9:08 PM

Can  you go ahead and create an issue for this and attach a sample project that reproduces the problem? I can probably get it fixed pretty quickly in that case.

May 10, 2011 at 8:16 AM

Thank you, I created a new issue with an attached repro project.

Coordinator
May 10, 2011 at 2:26 PM

Fixed in 15abbc3dec16  However, I noticed you also had a bug in the sample where the VM property and the Query String parameter were not named the same. You might want to check your original code to make sure that you have that right.