Click here to Skip to main content
15,881,791 members
Articles / Desktop Programming / WPF

A (Mostly) Declarative Framework for Building Simple WPF-based Wizards

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
7 Mar 2011LGPL322 min read 19.3K   229   15  
A declarative framework for building WPF wizards.
<local:DatabaseWizardPage x:Class="Olbert.Utilities.WPF.DatabasePage"
                          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:local="clr-namespace:Olbert.Utilities.WPF"
                          xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
                          x:Name="ThePage"
                          mc:Ignorable="d" 
                          d:DesignHeight="344" d:DesignWidth="389"
                          Title="Database Selection">
    <local:DatabaseWizardPage.Resources>
        <CollectionViewSource x:Key="DatabaseList" >
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="Name"/>
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

        <Style x:Key="LinkButtonStyle" TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <ControlTemplate.Resources>
                            <Style TargetType="{x:Type TextBlock}">
                                <Setter Property="TextDecorations" Value="Underline" />
                            </Style>
                        </ControlTemplate.Resources>
                        <ContentPresenter />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Foreground" Value="Blue" />
            <Setter Property="Cursor" Value="Hand" />
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter Property="Foreground" Value="Red" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </local:DatabaseWizardPage.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <TextBlock Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="4"
                   TextWrapping="Wrap"
                   Margin="3">Select a database by:<LineBreak/>
            - entering the name in the first textbox; or<LineBreak/>
            - selecting a grid entry after scanning for databases and clicking Use
        </TextBlock>
        <Button Name="btnMoreInfo" 
                Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="4"
                HorizontalAlignment="Left"
                Margin="3" 
                Style="{StaticResource LinkButtonStyle}" Click="btnMoreInfo_Click">more info</Button>
        <TextBlock Grid.Column="0" Grid.Row="2"
                   Margin="3">Enter database name</TextBlock>
        <TextBox Name="tbxDatabase" 
                 Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2"
                 Text="{Binding ElementName=ThePage, Path=Database}"
                 Margin="3" />
        <Button Name="btnTest"
                Grid.Column="3" Grid.Row="2"
                HorizontalAlignment="Left"
                IsEnabled="{Binding ElementName=tbxDatabase, Path=Text.Length}"
                Margin="3" Click="btnTest_Click">Test</Button>
        <TextBlock Grid.Column="0" Grid.Row="3" Grid.RowSpan="3"
                   Margin="3">Select a database</TextBlock>
        <ListBox Name="lbxDatabase"
                 Grid.Column="1" Grid.Row="4" Grid.ColumnSpan="2"
                 Margin="3"
                 SelectionMode="Single"
                 DisplayMemberPath="Name"
                 ItemsSource="{Binding Source={StaticResource DatabaseList}}" MouseDoubleClick="lbxDatabase_MouseDoubleClick" />
        <StackPanel Orientation="Vertical"
                    Grid.Column="3" Grid.Row="4">
            <Button Name="btnScanDB"
                HorizontalAlignment="Left"
                VerticalAlignment="Top"
                Margin="3" Click="btnScanDB_Click">Scan</Button>
            <Button Name="btnSelectDB"
                HorizontalAlignment="Left"
                VerticalAlignment="Top"
                    IsEnabled="{Binding ElementName=lbxDatabase, Path=SelectedItems.Count}"
                Margin="3" Click="btnSelectDB_Click">Use</Button>
        </StackPanel>
    </Grid>
</local:DatabaseWizardPage>

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)


Written By
Jump for Joy Software
United States United States
Some people like to do crossword puzzles to hone their problem-solving skills. Me, I like to write software for the same reason.

A few years back I passed my 50th anniversary of programming. I believe that means it's officially more than a hobby or pastime. In fact, it may qualify as an addiction Smile | :) .

I mostly work in C# and Windows. But I also play around with Linux (mostly Debian on Raspberry Pis) and Python.

Comments and Discussions