Composite Application Layer (PRISM) for WPF RRS feed

  • General discussion

  • I am following the example here: http://www.codeproject.com/KB/WPF/CompositeWpfApp.aspx

    If you look at the region diagram on the site you will see there are five regions. I am trying to remove the module selector region and have the server selector region manage the views in the main region instead. Essentially, when I click on a tab in the server selector I want to show a view associated with that tab in the main region. 

    If you look at the existing example, the ModuleSelectorPresentationMode.cs handles this by adding commands to the radio buttons in its constructor like this:

    // Defines Execute and CanExecute methods for radio buttons
          foreach (ImageRadioButton button in CommandSources((Panel)View.FindName(RadioButtonContainer)))
            button.Command = new DelegateCommand<string>(SelectModule, CanSelectModule);
          eventAggregator.GetEvent<ServerContextChangedEvent>().Subscribe(ServerContextChanged, ThreadOption.UIThread, true);
          eventAggregator.GetEvent<ServerContextClearedEvent>().Subscribe(ServerContextCleared, ThreadOption.UIThread, true);

    How can I mimic this in the server selector presentation model (I created since it isn't part of the existing example)? I cannot associate commands with the TabItems since you can't say TabItem.Command = new DelegateCommand<string>(SelectModule, CanSelectModule);

    Has anyone tried altering this example before? What I want should be very simple but I have spent a week on this with no success. I am looking for a PRISM solution with this infrastructure that only has the main menu region, tab selector region, main region, and status region. Please help! Thanks in advance.

    Thursday, May 13, 2010 12:09 PM

All replies

  • OK, I think I'm getting closer. I now have my TabControl implementing ICommandSource and am able to do the following:

    // Defines Execute and CanExecute methods for radio buttons
          foreach (TabItemClosable tabItemClosable in ((TabControl)View.FindName(RootTabControl)).Items)
            tabItemClosable.Command = new DelegateCommand<string>(SelectModule, CanSelectModule);

    The CommandParameter in xaml is passing the module name to be selected. However, I am not getting into the SelectModule method when I click a tab on the UI.

    When I run the sample project and put a breakpoint inside the SelectModule method, I always get there when clicking an ImageRadioButton. Why do I not get there now when clicking on a TabItem in my TabControl? Thanks.

    Thursday, May 13, 2010 1:36 PM
  • Needed to execute the command when clicking the TabItem.

    #region ICommandSource Members
        public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(TabItemClosable), new UIPropertyMetadata(null));
        public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register("CommandParameter", typeof(object), typeof(TabItemClosable), new UIPropertyMetadata(null));
        public static readonly DependencyProperty CommandTargetProperty = DependencyProperty.Register("CommandTarget", typeof(IInputElement), typeof(TabItemClosable), new UIPropertyMetadata(null));
        public ICommand Command
          get { return (ICommand)GetValue(CommandProperty); }
          set { SetValue(CommandProperty, value); }
        public object CommandParameter
          get { return (object)GetValue(CommandParameterProperty); }
          set { SetValue(CommandParameterProperty, value); }
        public IInputElement CommandTarget
          get { return (IInputElement)GetValue(CommandTargetProperty); }
          set { SetValue(CommandTargetProperty, value); }
        /// <summary>
        /// Executes the Command associated with this TabItemClosable, CommandParameter defined in TabSelectorView.xaml
        /// </summary>
        /// <param name="e">MouseButtonEventArgs</param>
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
          if (Command != null)

    Thursday, May 13, 2010 3:27 PM