none
[MVVM] Modal Window. 2 view in tabitem in modal window. RRS feed

  • Question

  • Hi there,

    I am busy porting a Windows Forms application to a WPF MVVM application and struck a problem for which I can't think of a proper way to solve this.

    I have a screen which handles registration of members. When the user click on the button a register a member, a modal window should open the details of the selected member in one tab and the availability of the member in a second tab. This tabcontrol with its two tabs should be in the modal window.

    I want to re-use my existing MVVM views for the member details and member availability in these tabitems, but I can't really figure a way to do this.

    I don't care about dialogresults and those things. I just want to open the modal window with the two views inside.

    The only option that I can think of is to have a child window on the registration view with a tab control and the views referenced in their tabitems.

    I hope this is clear enough.

    Wednesday, December 7, 2011 7:11 PM

Answers

  • Here is a suggestion of how to make a modal window.

    using System;
    using System.Windows;
    using System.Windows.Shapes;
    using System.ComponentModel;
    using System.Windows.Controls;
    using System.Collections.ObjectModel;
    using System.Windows.Input;
    
    namespace WpfApplication5
    {
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
        }
    
        public class MainWindowViewModel : INotifyPropertyChanged
        {
            Window modalWindow = new Window();
            public MainWindowViewModel()
            {
                Label label = new Label();
                label.Content = "Something here";
                modalWindow.Content = label;
            }
    
            public Command OpenModalWindow { get { return new Command(() => 
            {
                modalWindow.ShowDialog();
            }); } }
    
            public event PropertyChangedEventHandler PropertyChanged;
            public void RaiseChange(string PropertyName)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
            }
    
        }
    
        public class Command : ICommand
        {
            Action a;
            public Command(Action action)
            {
                a = action;
            }
            bool ICommand.CanExecute(object parameter)
            {
                return true;
            }
            event EventHandler ICommand.CanExecuteChanged
            {
                add {  }
                remove {  }
            }
    
            void ICommand.Execute(object parameter)
            {
                a.Invoke();
            }
        }
    }
    
    



    Developing is part of being a developer.
    Wednesday, December 7, 2011 8:27 PM

All replies

  • Here is a suggestion of how to make a modal window.

    using System;
    using System.Windows;
    using System.Windows.Shapes;
    using System.ComponentModel;
    using System.Windows.Controls;
    using System.Collections.ObjectModel;
    using System.Windows.Input;
    
    namespace WpfApplication5
    {
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
        }
    
        public class MainWindowViewModel : INotifyPropertyChanged
        {
            Window modalWindow = new Window();
            public MainWindowViewModel()
            {
                Label label = new Label();
                label.Content = "Something here";
                modalWindow.Content = label;
            }
    
            public Command OpenModalWindow { get { return new Command(() => 
            {
                modalWindow.ShowDialog();
            }); } }
    
            public event PropertyChangedEventHandler PropertyChanged;
            public void RaiseChange(string PropertyName)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
            }
    
        }
    
        public class Command : ICommand
        {
            Action a;
            public Command(Action action)
            {
                a = action;
            }
            bool ICommand.CanExecute(object parameter)
            {
                return true;
            }
            event EventHandler ICommand.CanExecuteChanged
            {
                add {  }
                remove {  }
            }
    
            void ICommand.Execute(object parameter)
            {
                a.Invoke();
            }
        }
    }
    
    



    Developing is part of being a developer.
    Wednesday, December 7, 2011 8:27 PM
  • Hi Marias van Zyl,

    We have not heard from you in a couple of days.

    Please post back at your convenience if we can assist further.

    Enjoy your day!


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Monday, December 12, 2011 2:02 AM
    Moderator