Click here to Skip to main content
15,884,838 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 7:35
professionalKevin Marois30-Dec-13 7:35 
GeneralRe: WPF DialogService Question Pin
Ron Beyer30-Dec-13 7:46
professionalRon Beyer30-Dec-13 7:46 
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 7:53
professionalKevin Marois30-Dec-13 7:53 
GeneralRe: WPF DialogService Question Pin
Ron Beyer30-Dec-13 8:03
professionalRon Beyer30-Dec-13 8:03 
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 8:08
professionalKevin Marois30-Dec-13 8:08 
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 8:45
professionalKevin Marois30-Dec-13 8:45 
GeneralRe: WPF DialogService Question Pin
Ron Beyer30-Dec-13 8:54
professionalRon Beyer30-Dec-13 8:54 
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 9:18
professionalKevin Marois30-Dec-13 9:18 
Yes it is.

One thing I forgot was the Owner window. So I added an overload.

public static DialogResultEx ShowDialog<TViewModelType>(TViewModelType viewModel) where TViewModelType : _DialogBaseViewModel
{
    Type dialogType = registry.Where(x => x.Value == viewModel.GetType()).Select(x => x.Key).FirstOrDefault();

    if (dialogType == null)
    {
        throw new ArgumentException(string.Format("There is no registered dialog corresponding to a view model of type {0}.", viewModel));
    }

    var dialog = (Window)Activator.CreateInstance(dialogType);

    dialog.DataContext = viewModel;
    dialog.ShowDialog();

    DialogResultEx dlgResult = new DialogResultEx();
    dlgResult.DialogResult = dialog.DialogResult;
    dlgResult.DialogData = viewModel.DialogData;

    return dlgResult;
}




public static DialogResultEx ShowDialog<TViewModelType, TOwnerType>(TViewModelType viewModel, Type ownerType) where TViewModelType : _DialogBaseViewModel
{
    Type dialogType = registry.Where(x => x.Value == viewModel.GetType()).Select(x => x.Key).FirstOrDefault();

    if (dialogType == null)
    {
        throw new ArgumentException(string.Format("There is no registered dialog corresponding to a view model of type {0}.", viewModel));
    }



    var dialog = (Window)Activator.CreateInstance(dialogType);

    dialog.DataContext = viewModel;

    if (ownerType != null)
    {
        Window ownerWindow = FindWindow(ownerType);
        dialog.Owner = ownerWindow;
    }

    dialog.ShowDialog();

    DialogResultEx dlgResult = new DialogResultEx();
    dlgResult.DialogResult = dialog.DialogResult;
    dlgResult.DialogData = viewModel.DialogData;

    return dlgResult;
}


Usage:
DialogResultEx dialogResult1 = DialogService.ShowDialog<SQLConnectionViewModel>(new SQLConnectionViewModel());

DialogResultEx dialogResult2 = DialogService.ShowDialog<SQLConnectionViewModel, MainWindowView>(new SQLConnectionViewModel(), typeof(MainWindowView));


Given the generics, how do I combine this into one method?
If it's not broken, fix it until it is

GeneralRe: WPF DialogService Question Pin
Ron Beyer30-Dec-13 10:25
professionalRon Beyer30-Dec-13 10:25 
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 10:28
professionalKevin Marois30-Dec-13 10:28 
GeneralRe: WPF DialogService Question Pin
Kevin Marois31-Dec-13 5:54
professionalKevin Marois31-Dec-13 5:54 
GeneralRe: WPF DialogService Question Pin
Ron Beyer31-Dec-13 6:09
professionalRon Beyer31-Dec-13 6:09 
GeneralRe: WPF DialogService Question Pin
Mycroft Holmes6-Jan-14 21:57
professionalMycroft Holmes6-Jan-14 21:57 
QuestionConvert BitmapImage into byte arrays in wpf Pin
Member 1001614027-Dec-13 0:23
Member 1001614027-Dec-13 0:23 
AnswerRe: Convert BitmapImage into byte arrays in wpf Pin
Pete O'Hanlon27-Dec-13 0:58
mvePete O'Hanlon27-Dec-13 0:58 
GeneralRe: Convert BitmapImage into byte arrays in wpf Pin
Member 1001614027-Dec-13 3:44
Member 1001614027-Dec-13 3:44 
QuestionWPF App Content Presenter in Main Window Pin
Kevin Marois23-Dec-13 7:21
professionalKevin Marois23-Dec-13 7:21 
AnswerRe: WPF App Content Presenter in Main Window Pin
SledgeHammer0123-Dec-13 10:22
SledgeHammer0123-Dec-13 10:22 
GeneralRe: WPF App Content Presenter in Main Window Pin
Kevin Marois3-Jan-14 10:29
professionalKevin Marois3-Jan-14 10:29 
QuestionHow to add certificate in Local Machine Pin
Sugu.s19-Dec-13 22:50
Sugu.s19-Dec-13 22:50 
QuestionWPF user control not working Pin
sridhar chanti18-Dec-13 2:33
sridhar chanti18-Dec-13 2:33 
SuggestionRe: WPF user control not working Pin
Matt T Heffron18-Dec-13 7:38
professionalMatt T Heffron18-Dec-13 7:38 
QuestionSILVER LIGHT Pin
Member 1047161416-Dec-13 23:16
Member 1047161416-Dec-13 23:16 
AnswerRe: SILVER LIGHT Pin
Pete O'Hanlon16-Dec-13 23:44
mvePete O'Hanlon16-Dec-13 23:44 
GeneralRe: SILVER LIGHT Pin
Mycroft Holmes17-Dec-13 0:05
professionalMycroft Holmes17-Dec-13 0:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.