This project is read-only.

Dialog Service

The DialogService class priovdes:
  • ShowMessage for MessageBoxes
  • ShowOpenFileDialog for OpenFileDialog
  • ShowSaveFileDialog for SaveFileDialog.

Window Service

To use a custom dialog in a lously coupled way, only a few steps have to be done.

1. Create a ViewModel for the dialog implementing IWindowViewModel

    public class AddedViewModel : IWindowViewModel
    {
        public bool Closed { get; set; }

        public string Title
        {
            get { return "Added!"; }
        }

        public string Message
        {
            get { return "A person has been added to the table."; }
        }
    }
Remark
Setting Closed property to true will close the dialog!

2. Create a View for the dialog as a UserControl

<UserControl x:Class="MvvmLightSample.AddedView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:vm="clr-namespace:MvvmLightSample.ViewModel"
             mc:Ignorable="d"
             d:DesignHeight="20" d:DesignWidth="300"
             d:DataContext="{d:DesignInstance vm:AddedViewModel, IsDesignTimeCreatable=True}">
    <Grid>
        <TextBlock Text="{Binding Message}" />
    </Grid>
</UserControl>


3. Add a DataTemplate for the dialog in App.Resources

    <Application.Resources>
        <!-- other resources -->

        <DataTemplate DataType="{x:Type vm:AddedViewModel}">
            <v:AddedView />
        </DataTemplate>
    </Application.Resources>


4. Use the WindowService with you ViewModel for a custom modal dialog

var addedVM = new AddedViewModel()
windowService.ShowDialog(addedVM);
Remark
You can add a result property in dialog's ViewModel.

Last edited Oct 18, 2014 at 1:29 PM by Pellared, version 14

Comments

No comments yet.