Simple way of showing Msgbox and Dialogs in WPF MVVM

I know that MVVM purists say that you should not use messageboxes and Dialogs in a MVVM application , however as a business developer you must sometimes blok the GUI to let the user pick an item or confirm there actions . After some discussions in the comunity i decided to show y

 
 
 
 
 
4 Star
(1)
3,564 times
Add to favorites
3/26/2011
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

VB.NET
<UserControl x:Class="VBDC.View.TabView"
             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" 
             mc:Ignorable="d" 
             d:DesignHeight="600" d:DesignWidth="800">
    <UserControl.Resources>
        <Style x:Key="ColRightAlignStyle" TargetType="{x:Type TextBlock}">
            <Setter Property="TextAlignment" Value="Right" />
            <Setter Property="Padding" Value="5,0"/>
            <Setter Property="VerticalAlignment" Value="Center" />
        </Style>
        <Style x:Key="ColLeftAlignStyle" TargetType="{x:Type TextBlock}">
            <Setter Property="TextAlignment" Value="Left" />
            <Setter Property="Padding" Value="5,0"/>
            <Setter Property="VerticalAlignment" Value="Center" />
        </Style>
    </UserControl.Resources>
    <Grid>
        <TabControl  HorizontalAlignment="Stretch" Margin="4,4,4,4" Name="TabCtrlMain" VerticalAlignment="Stretch" >
            <TabItem Header="Msgbox" Name="TabOverzicht" Cursor="Hand">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="100" />
                        <RowDefinition Height="80" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Button Command="{Binding MsgboxDemoCommand}" Content="Show confirm" Grid.Row="1" Height="23" HorizontalAlignment="Left"  Margin="298,21,0,0" Name="BtnMsgboxDemo" VerticalAlignment="Top" Width="120">
                        <Button.ToolTip>
                            <StackPanel Background="white" Height="100" Width="200">
                                <StackPanel Background="Orange" Height="30" HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Top" Width="200">
                                    <TextBlock FontFamily="Aharoni" FontSize="24" FontWeight="Bold" Foreground="Black" Height="30" HorizontalAlignment="Right" TextWrapping="Wrap" VerticalAlignment="Top" Width="143"><Run FontFamily="Andalus" FontSize="18" FontWeight="Normal" Text=" Shows confirmation msgbox" /></TextBlock>
                                </StackPanel>
                                <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Top" Width="200">
                                    <TextBlock Background="{x:Null}" Foreground="#FFF9F4F4" Height="98" HorizontalAlignment="Right" TextAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Width="181"><Run FontFamily="Verdana" FontSize="11" FontWeight="Normal" Foreground="#FF151514" Text="This shows how you can interact with the user through a mgsbox" /></TextBlock>
                                </StackPanel>
                            </StackPanel>
                        </Button.ToolTip>
                    </Button>
                </Grid>
            </TabItem>
            <TabItem Header="Dialog" Cursor="Hand" >
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="100" />
                        <RowDefinition Height="80" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Button Command="{Binding DialogDemoCommand}" Content="Show Dialog" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="298,21,0,0" Name="BtnProp" VerticalAlignment="Top" Width="120">
                        <Button.ToolTip>
                            <StackPanel Background="white" Height="100" Width="200">
                                <StackPanel Background="orange" Height="30" Width="200" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" >
                                 <TextBlock FontFamily="Aharoni" FontSize="24" FontWeight="Bold" Foreground="Black" TextWrapping="Wrap" VerticalAlignment="Top" Height="30" HorizontalAlignment="Right" Width="143">
                                         <Run FontFamily="Andalus" FontSize="18" FontWeight="Normal" Text=" Dialog " />
                                    </TextBlock>
                                </StackPanel>
                                <StackPanel Width="200"  Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" >
                                    <TextBlock TextWrapping="Wrap" Foreground="#FFF9F4F4" TextAlignment="Left"  Background="{x:Null}" HorizontalAlignment="Right" VerticalAlignment="Top" Width="181" Height="98">
                                    <Run FontFamily="Verdana" FontSize="11" FontWeight="Normal" Foreground="#FF151514" 
                                    Text="Shows a copy of this window as a dialog"/>
                                    </TextBlock>
                                </StackPanel>
                            </StackPanel>
                        </Button.ToolTip>
                    </Button>
                    <Label Content="Look at inmediate window for messages and finalization" Height="28" HorizontalAlignment="Left" Margin="39,40,0,0" Name="label1" VerticalAlignment="Top" />
                </Grid>
            </TabItem>
        </TabControl>
    </Grid>
</UserControl>