0
votes

I'm a beginner and I have a very simple WPF application with two views... (I use code behind for now...)

I need to to the same thing than this tutorial , but using Prism instead of mvvm light... What do I have to change ?

I manage to use commands, but I don't know how to swtich the view... (ViewModelBase doesn't exist in Prism) I need to change the view from a command in the ViewModel of my first view.

I only find diffcult Prism "Get started" tutorials... I'm looking for a very simple example...

1
There's a very simple, but complete, application that uses Prism and MOQ here. wpfpasswordgeneratorprismoq.codeplex.com It is intended as a reference application for people wanting a simple, but useful, starting point.Gayot Fow

1 Answers

1
votes

Simple example ;) Have you check this out? http://msdn.microsoft.com/en-us/library/gg406140.aspx It's a long read, but is packed with information. The latest release of Prism introduced BindableBase, which uses a SetProperty(ref _propName, value) type syntax which makes the INotifyProperty Change ordeal much cleaner.

Listing 16: Code Samples Using the PRISM Library for WPF, should provide you with the simple examples you desire. They've added several more examples in 5.0 than what was available previous with the stock trader app.

You can do view first region navigation then simply like this.

     <Button Content="Steady State Projects"  
        Style="{StaticResource NavButton}"
        Command="{x:Static infCommands:ApplicationCommands.NavigateCommand}" 
        CommandParameter="{x:Type views:Projects }" MaxHeight="75"/>

  public class ApplicationCommands
  {
    public static CompositeCommand NavigateCommand = new CompositeCommand();
  }

  public class ShellViewModel
  {
    private readonly IRegionManager _regionManager;

    public DelegateCommand<object> NavigateCommand { get; private set; }

    public ShellViewModel(IRegionManager regionManager)
    {
        _regionManager = regionManager;
        NavigateCommand = new DelegateCommand<object>(Navigate);
        ApplicationCommands.NavigateCommand.RegisterCommand(NavigateCommand);
    }

    /// <summary>Navigates using the view path, with the regions</summary>
    /// <param name="navigatePath"></param>
    private void Navigate(object navigatePath)
    {
        if (navigatePath != null)
        {
            _regionManager.RequestNavigate(RegionNames.ContentRegion, navigatePath.ToString(), NavigationComplete);
        }
    }

    /// <summary>Callback activates on navigation completed.</summary>
    /// <param name="result"></param>
    private void NavigationComplete(NavigationResult result)
    {
        // MessageBox.Show(result.Context.Uri.ToString());
    }
 }