Click here to Skip to main content
15,893,487 members
Articles / Desktop Programming / WPF

A Prism 4 Application Checklist

Rate me:
Please Sign up or sign in to vote.
4.92/5 (50 votes)
5 Apr 2011CPOL18 min read 169.9K   7.5K   169  
The article provides a step-by-step explanation of how to set up a Prism application.
<ribbon:RibbonWindow x:Class="Prism4Demo.Shell.Views.ShellWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
        xmlns:prism="http://www.codeplex.com/prism"
        Title="Prism 4 Demo"
		Width="800" Height="600">

    <!-- Window Resources -->
    <ribbon:RibbonWindow.Resources>
        <LinearGradientBrush x:Key="WindowBackgroundBrush">
            <GradientStop Color="#FFE7E9EB" Offset="0" />
            <GradientStop Color="#FFC6CACF" Offset="1" />
        </LinearGradientBrush>
    </ribbon:RibbonWindow.Resources>

    <ribbon:RibbonWindow.Background>
        <StaticResource ResourceKey="WindowBackgroundBrush" />
    </ribbon:RibbonWindow.Background>

    <!-- Layout Root -->
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition x:Name="RibbonRow" Height="Auto"/>
            <RowDefinition x:Name="ClientRow" Height="*"/>
        </Grid.RowDefinitions>
        
        <!-- Note that the application Ribbon is defined as a Prism region, so that modules can
             load their own tabs into the Ribbon. The Utility folder contains a RibbonRegionAdapter
             class that enables the Ribbon to act as a Prism region. -->

        <!-- Application Ribbon -->
<ribbon:Ribbon x:Name="ApplicationRibbon" 
                Grid.Row="0"  
                Background="Transparent"  
                prism:RegionManager.RegionName="RibbonRegion">
            
            <!-- Ribbon ApplicationMenu (defined here) -->
            <ribbon:Ribbon.ApplicationMenu>
                <ribbon:RibbonApplicationMenu SmallImageSource="Images\ribbon.png">
                    <ribbon:RibbonApplicationMenuItem Header="Hello _Ribbon"
                                                      x:Name="MenuItem1"
                                                      ImageSource="Images\LargeIcon.png"/>
                </ribbon:RibbonApplicationMenu>
            </ribbon:Ribbon.ApplicationMenu>

            <!-- Ribbon QuickAccessToolbar  (defined here) -->
            <ribbon:Ribbon.QuickAccessToolBar>
                <ribbon:RibbonQuickAccessToolBar>
                    <ribbon:RibbonButton Command="{Binding NewCollection}" ToolTip="Create a new file (Ctrl+N)" SmallImageSource="Images\new.png" />
                    <ribbon:RibbonButton Command="{Binding OpenCollection}" ToolTip="Open an existing file (Ctrl+O)" SmallImageSource="Images\open.png" />
                    <ribbon:RibbonButton Command="{Binding SaveCollection}" ToolTip="Save the current file (Ctrl+S)" SmallImageSource="Images\save.png" />
                    <ribbon:RibbonButton Command="{Binding PrintNote}" ToolTip="Print the current file (Ctrl+P)" SmallImageSource="Images\print.png" />
                </ribbon:RibbonQuickAccessToolBar>
            </ribbon:Ribbon.QuickAccessToolBar>

            <!-- Home Tab (defined here) -->
            <ribbon:RibbonTab x:Name="HomeTab"  Header="Home">
                <ribbon:RibbonGroup Header="Group S1">
                    <ribbon:RibbonButton LargeImageSource="Images\LargeIcon.png" Label="Button S1" />
                    <ribbon:RibbonButton SmallImageSource="Images\SmallIcon.png" Label="Button S2" />
                    <ribbon:RibbonButton SmallImageSource="Images\SmallIcon.png" Label="Button S3" />
                    <ribbon:RibbonButton SmallImageSource="Images\SmallIcon.png" Label="Button S4" />
                </ribbon:RibbonGroup>
            </ribbon:RibbonTab>
        </ribbon:Ribbon> 
        
        <!-- Client Area -->
        <Grid x:Name="ClientArea" Grid.Row="1">

            <!-- Grid Layout -->
            <Grid.ColumnDefinitions>
                <ColumnDefinition x:Name="NavigationColumn" Width="0.200*"/>
                <ColumnDefinition x:Name="WorkspaceColumn" Width="0.600*"/>
            </Grid.ColumnDefinitions>
            <GridSplitter HorizontalAlignment="Left" Width="5" Grid.Column="1"/>

            <!-- Navigation Pane Grid -->
            <Grid x:Name="NavigationPane">

                <!-- Grid Layout -->
                <Grid.RowDefinitions>
                    <RowDefinition x:Name="Navigator" Height="*"/>
                    <RowDefinition x:Name="TaskButtons" Height="Auto"/>
                </Grid.RowDefinitions>

                <!-- Navigator Region -->
                <ContentControl x:Name="NavigatorRegion" Grid.Row="0" prism:RegionManager.RegionName="NavigatorRegion" />

                <!-- Task Button Region -->
                <StackPanel Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="0,0,0,5">
                    <Border Background="{StaticResource WindowBackgroundBrush}" BorderBrush="DarkGray" BorderThickness="1" Height="5" Width="Auto" HorizontalAlignment="Stretch" Margin="5,0,5,5"/>
                    <ItemsControl x:Name="TaskButtonRegion" prism:RegionManager.RegionName="TaskButtonRegion" HorizontalAlignment="Stretch" VerticalAlignment="Top" />
                </StackPanel>

            </Grid>

            <!-- Workspace Region-->
            <ContentControl x:Name="WorkspaceRegion" Grid.Column="1" prism:RegionManager.RegionName="WorkspaceRegion" />

        </Grid>

    </Grid>
</ribbon:RibbonWindow>

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)


Written By
Software Developer (Senior) Foresight Systems
United States United States
David Veeneman is a financial planner and software developer. He is the author of "The Fortune in Your Future" (McGraw-Hill 1998). His company, Foresight Systems, develops planning and financial software.

Comments and Discussions