Click here to Skip to main content
12,635,232 members (24,047 online)
Click here to Skip to main content

Stats

161.1K views
2.5K downloads
116 bookmarked
Posted

WPF Common TaskDialog for Vista and XP

, 30 Dec 2007 CPOL
WPF custom TaskDialog that renders the same on Vista and XP. This custom dialog simplifies programming by providing a simple interface for developers that is not Operating System dependent. This solution does not use the Windows API for rendering.
<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="CustomDialogWindow"
    Title="CommonDialog" Height="Auto" Width="380"
    Background="{x:Null}"
    SnapsToDevicePixels="True" SizeToContent="Height" WindowStartupLocation="CenterScreen"
    Margin="0,0,0,0"
    WindowStyle="None"
    >
    <Border x:Name="borderCustomDialog" Background="{x:Null}" CornerRadius="0,0,0,0" Padding="0,0,0,0">
        <StackPanel Margin="0,0,0,0" Width="Auto" Height="Auto">
            <TextBlock x:Name="tbCaption" VerticalAlignment="Center" Height="Auto" FontFamily="Arial" Text="Caption" TextTrimming="WordEllipsis" TextWrapping="NoWrap" Foreground="#FF000000" Padding="4,6,0,6"/>
            <Grid Background="White" Width="Auto" Height="Auto" Margin="0,-1,0,0">

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Image HorizontalAlignment="Left" Margin="10,10,10,10" x:Name="imgInstructionIcon" VerticalAlignment="Top" Width="Auto" Height="Auto" Source="CustomDialogInformation.png" Grid.ColumnSpan="1" Grid.Row="0"/>
                <TextBlock HorizontalAlignment="Stretch" Margin="0,0,0,0" x:Name="tbInstructionHeading" VerticalAlignment="Center" Width="Auto" Text="Instruction Heading" TextWrapping="Wrap" Grid.Column="1" Grid.ColumnSpan="1" Grid.RowSpan="1" FontFamily="Arial" FontSize="18" Foreground="#FF006ECD"/>
                <TextBlock HorizontalAlignment="Stretch" x:Name="tbInstructionText" Width="Auto" FontFamily="Arial" Text="Instruction" TextWrapping="Wrap" Grid.Column="1" Grid.ColumnSpan="1" Grid.Row="1" Grid.RowSpan="1"/>
                <TextBlock x:Name="tbAdditionalDetailsText" VerticalAlignment="Stretch" Height="Auto" Text="Additional Details Text" TextWrapping="Wrap" Margin="0,10,0,0" FontFamily="Arial" Grid.Column="1" Grid.Row="2" Visibility="Collapsed"/>
                <Border Margin="0,10,0,0" VerticalAlignment="Top" Height="Auto" Background="#FFECECEC" BorderBrush="#FFC9C9C9" BorderThickness="0,1,0,1" Padding="8,0,0,0" Grid.ColumnSpan="2" Grid.Row="3">
                    <DockPanel Margin="0,8,0,8" Width="Auto" Height="Auto" Background="{x:Null}">
                        <Expander ClipToBounds="False" HorizontalAlignment="Left" x:Name="expAdditionalDetails" VerticalAlignment="Center" FontFamily="Arial" Header="See Details">
                            <Grid Margin="0,0,0,0" Width="Auto"/>
                        </Expander>
                        <Button x:Name="btnCancel" Width="60" Height="Auto" Content="Cancel" HorizontalAlignment="Right" Margin="0,0,8,0" VerticalAlignment="Center" DockPanel.Dock="Right"/>

                        <Button x:Name="btnNo" Width="60" Height="Auto" Content="No" HorizontalAlignment="Right" Margin="0,0,8,0" VerticalAlignment="Center" DockPanel.Dock="Right"/>

                        <Button x:Name="btnYes" Width="60" Height="Auto" Content="Yes" HorizontalAlignment="Right" Margin="0,0,8,0" VerticalAlignment="Center" DockPanel.Dock="Right"/>

                        <Button x:Name="btnOK" Width="60" Height="Auto" Content="OK" HorizontalAlignment="Right" Margin="0,0,8,0" VerticalAlignment="Center" DockPanel.Dock="Right"/>

                        <ProgressBar HorizontalAlignment="Right" Margin="0,0,10,0" x:Name="pbDisabledButtonsProgressBar" Width="75" Height="10" DockPanel.Dock="Right" SmallChange="1"/>

                    </DockPanel>
                </Border>
                <Border HorizontalAlignment="Stretch" Margin="0,0,0,0" Width="Auto" Background="#FFECECEC" BorderBrush="#FFF4F4F4" BorderThickness="0,1,0,0" Grid.ColumnSpan="2" Grid.Row="4" Grid.RowSpan="1">
                    <StackPanel Height="Auto" Orientation="Horizontal">
                        <Image RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Left" x:Name="imgFooterIcon" VerticalAlignment="Center" Width="Auto" Height="Auto" Source="CustomDialogInformation.png">
                            <Image.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform ScaleX="0.5" ScaleY="0.5"/>
                                    <SkewTransform AngleX="0" AngleY="0"/>
                                    <RotateTransform Angle="0"/>
                                    <TranslateTransform X="0" Y="0"/>
                                </TransformGroup>
                            </Image.RenderTransform>
                        </Image>
                        <TextBlock HorizontalAlignment="Stretch" x:Name="tbFooterText" VerticalAlignment="Center" FontFamily="Arial" Text="Footer Text" TextWrapping="Wrap"/>
                    </StackPanel>
                </Border>
            </Grid>
        </StackPanel>
    </Border>
</Window>

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 Code Project Open License (CPOL)

Share

About the Author

Karl Shifflett
Architect Infragistics
United States United States

I’m a passionate Platform Architect at Infragistics.


I’m a long-time WPF-Prism fanatic who enjoys writing developer tools and line of business applications.


My current front end passions are: XAML platforms (Xamarin.Forms, Xamarin, UWP, and WPF), Electron, ES2015 (ES6), Node.js, Aurelia, and AngularJS (Angular 1.5.x).


For the back end I use what is appropriate for the project: SQL Server and ASP.NET WebAPI, MongoDB, Express, Azure, Firebase, etc.


I am very pragmatic software engineer and strive to write simple, maintainable, and testable code. Simple code allows for solving complex problems in a maintainable way.


My Blog


My Github Repros


My YouTube Videos


Just a grain of sand on the worlds beaches.


You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161208.2 | Last Updated 30 Dec 2007
Article Copyright 2007 by Karl Shifflett
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid