Click here to Skip to main content
12,998,892 members (70,903 online)
Click here to Skip to main content

Stats

200.1K views
8.5K downloads
89 bookmarked
Posted 17 May 2009

WPF Modal Dialog

, 17 Mar 2013
How to set up a modal (blocking) dialog inside a WPF window.
<UserControl x:Class="Technewlogic.Samples.WpfModalDialog.ModalDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	x:Name="root">

	<Grid DataContext="{Binding ElementName=root}">
		<Border Background="#90000000" Visibility="{Binding Visibility}">
			<Border BorderBrush="Black" BorderThickness="1" Background="AliceBlue" 
					CornerRadius="10,0,10,0" VerticalAlignment="Center"
					HorizontalAlignment="Center">
				<Border.BitmapEffect>
					<DropShadowBitmapEffect Color="Black" Opacity="0.5" Direction="270" ShadowDepth="0.7" />
				</Border.BitmapEffect>
				<Grid Margin="10">
					<Grid.RowDefinitions>
						<RowDefinition />
						<RowDefinition Height="Auto" />
					</Grid.RowDefinitions>
					<TextBlock x:Name="MessageTextBlock" Text="{Binding Message}" TextWrapping="Wrap" Margin="5" />
					<UniformGrid Grid.Row="1" Margin="5" Columns="2" HorizontalAlignment="Center"
								 VerticalAlignment="Bottom">
						<Button x:Name="OkButton" Click="OkButton_Click" Content="Ok" Margin="2"  />
						<Button x:Name="CancelButton" Click="CancelButton_Click" Content="Cancel" Margin="2" />
					</UniformGrid>
				</Grid>
			</Border>
		</Border>
	</Grid>
	
</UserControl>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

Share

About the Author

Ronald Schlenker
Software Developer (Senior) www.technewlogic.de
Germany Germany
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170622.1 | Last Updated 18 Mar 2013
Article Copyright 2009 by Ronald Schlenker
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid