Click here to Skip to main content
15,849,182 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 7:56
professionalKevin Marois30-Dec-13 7:56 
SuggestionRe: WPF DialogService Question Pin
Ron Beyer30-Dec-13 6:39
professionalRon Beyer30-Dec-13 6:39 
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 7:56
professionalKevin Marois30-Dec-13 7:56 
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 8:06
professionalKevin Marois30-Dec-13 8:06 
GeneralRe: WPF DialogService Question Pin
Ron Beyer30-Dec-13 8:22
professionalRon Beyer30-Dec-13 8:22 
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 8:22
professionalKevin Marois30-Dec-13 8:22 
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 8:35
professionalKevin Marois30-Dec-13 8:35 
GeneralRe: WPF DialogService Question Pin
Ron Beyer30-Dec-13 8:46
professionalRon Beyer30-Dec-13 8:46 
I would add another class, something like:

C#
public class DialogResultEx
{
    public bool? DialogResult { get; set; }
    public object DialogData { get; set; }
}


Then in your ShowDialog method:

C#
public static DialogResultEx ShowDialog<TViewModelType>(TViewModelType viewModel) where TViewModelType : _DialogBaseViewModel
    {
        Type dialogType = registry.Where(x => x.Value == viewModel.GetType()).Select(x => x.Key).FirstOrDefault();
        var dialog = (Window)Activator.CreateInstance(dialogType);
 
        dialog.DataContext = viewModel;
        dialog.ShowDialog();
            
        DialogResultEx dlgResult = new DialogResult();
        dlgResult.DialogResult = dialog.DialogResult;
        dlgResult.DialogData = viewModel.WhateverData;    //Modify as needed
 
        return dlgResult;
    }


You could even make it implicitly castable to a bool...

C#
public class DialogResultEx
{
    public bool? DialogResult { get; set; }
    public object DialogData { get; set; }

    public static implicit operator bool?(DialogResultEx dlgResult)
    {
        return dlgResult.DialogResult;
    }
}


So you wouldn't have to change much of your upstream code that didn't need the entire class.
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 8:53
professionalKevin Marois30-Dec-13 8:53 
GeneralRe: WPF DialogService Question Pin
Ron Beyer30-Dec-13 9:03
professionalRon Beyer30-Dec-13 9:03 
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 9:08
professionalKevin Marois30-Dec-13 9:08 
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 9:45
professionalKevin Marois30-Dec-13 9:45 
GeneralRe: WPF DialogService Question Pin
Ron Beyer30-Dec-13 9:54
professionalRon Beyer30-Dec-13 9:54 
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 10:18
professionalKevin Marois30-Dec-13 10:18 
GeneralRe: WPF DialogService Question Pin
Ron Beyer30-Dec-13 11:25
professionalRon Beyer30-Dec-13 11:25 
GeneralRe: WPF DialogService Question Pin
Kevin Marois30-Dec-13 11:28
professionalKevin Marois30-Dec-13 11:28 
GeneralRe: WPF DialogService Question Pin
Kevin Marois31-Dec-13 6:54
professionalKevin Marois31-Dec-13 6:54 
GeneralRe: WPF DialogService Question Pin
Ron Beyer31-Dec-13 7:09
professionalRon Beyer31-Dec-13 7:09 
GeneralRe: WPF DialogService Question Pin
Mycroft Holmes6-Jan-14 22:57
professionalMycroft Holmes6-Jan-14 22:57 
QuestionConvert BitmapImage into byte arrays in wpf Pin
Member 1001614027-Dec-13 1:23
Member 1001614027-Dec-13 1:23 
AnswerRe: Convert BitmapImage into byte arrays in wpf Pin
Pete O'Hanlon27-Dec-13 1:58
subeditorPete O'Hanlon27-Dec-13 1:58 
GeneralRe: Convert BitmapImage into byte arrays in wpf Pin
Member 1001614027-Dec-13 4:44
Member 1001614027-Dec-13 4:44 
QuestionWPF App Content Presenter in Main Window Pin
Kevin Marois23-Dec-13 8:21
professionalKevin Marois23-Dec-13 8:21 
AnswerRe: WPF App Content Presenter in Main Window Pin
SledgeHammer0123-Dec-13 11:22
SledgeHammer0123-Dec-13 11:22 
GeneralRe: WPF App Content Presenter in Main Window Pin
Kevin Marois3-Jan-14 11:29
professionalKevin Marois3-Jan-14 11:29 

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.