Click here to Skip to main content
15,886,199 members
Articles / Desktop Programming / WPF

MPP Viewer

Rate me:
Please Sign up or sign in to vote.
4.75/5 (13 votes)
15 Jun 2011CPOL3 min read 103.5K   4.1K   41  
MPP Viewer is a simple viewer for Microsoft Project files. I works well with 2000/2003/2007 file formats.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:view="clr-namespace:ProjectViewer.Views"
                    x:Class="ProjectViewer.MainWindowResources"
                    xmlns:viewModel="clr-namespace:ProjectViewer.ViewModel">



    <DataTemplate DataType="{x:Type viewModel:GanttChartViewModel}">
        <view:GanttView />
    </DataTemplate>

    <DataTemplate DataType="{x:Type viewModel:TasksViewModel}">
        <view:AllTasksView />
    </DataTemplate>
    
    <DataTemplate DataType="{x:Type viewModel:ResourceSheetViewModel}">
        <view:ResourceSheetView />
    </DataTemplate>
    
    <DataTemplate DataType="{x:Type viewModel:ProjectViewModel}">
        <view:ProjectView />
    </DataTemplate>
    
    <DataTemplate DataType="{x:Type viewModel:ResourceViewModel}">
        <view:ResourceDetailsView />
    </DataTemplate>
    
    <DataTemplate DataType="{x:Type viewModel:TaskViewModel}">
        <view:TaskDetailsView />
    </DataTemplate>
    
    <DataTemplate DataType="{x:Type viewModel:LicenseViewModel}">
        <view:LicenseView />
    </DataTemplate>
    
    <DataTemplate DataType="{x:Type viewModel:AboutViewModel}">
        <view:AboutView />
    </DataTemplate>
    
    <!-- 
    This style configures both of the main content areas in the main window.
    -->
    <Style x:Key="MainHCCStyle" TargetType="{x:Type HeaderedContentControl}">
        <Setter Property="HeaderTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Border Background="{StaticResource Brush_HeaderBackground}" 
                            BorderBrush="LightGray" 
                            BorderThickness="0,0,0,1" 
                            CornerRadius="5,5,2,2" 
                            Padding="4" 
                            SnapsToDevicePixels="True" 
                            >
                        <TextBlock FontSize="14" FontWeight="Bold" HorizontalAlignment="Center" Text="{TemplateBinding Content}" />
                    </Border>
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <!-- 
        This template ensures that content of a HeaderedContentControl 
        fills the available vertical space. 
        -->
                <ControlTemplate TargetType="{x:Type HeaderedContentControl}">
                    <DockPanel>
                        <!--<ContentPresenter DockPanel.Dock="Top"
                                          ContentSource="Header" 
                                          ContentTemplate="{TemplateBinding HeaderTemplate}" 
                                          />-->
                        <ContentPresenter ContentSource="Content" ContentTemplate="{TemplateBinding ContentTemplate}" />
                    </DockPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--
    This style ensures that the borders in the main window are consistent.
    -->
    <Style x:Key="MainBorderStyle" TargetType="{x:Type Border}">
        <Setter Property="Background" Value="WhiteSmoke" />
        <Setter Property="BorderBrush" Value="LightGray" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="CornerRadius" Value="5" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
    </Style>

    <!--
    This template explains how to render the list of commands on the left
    side in the main window (the 'Control Panel' area).
    -->
    <DataTemplate x:Key="CommandsTemplate">
        <ItemsControl IsTabStop="False" ItemsSource="{Binding}" Margin="2">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Command="{Binding Path=Command}" Margin="1" Width="50" Height="50">
                        <StackPanel >
                            <Image Source="{Binding Path=ImagePath}" Width="30" Height="30" />
                            <TextBlock Text="{Binding Path=DisplayName}" Margin="1, 0, 2, 1" HorizontalAlignment="Center" FontSize="10" />
                        </StackPanel>
                    </Button>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </DataTemplate>

    <!-- 
  This template explains how to render 
  a tab item with a close button.
  -->
    <DataTemplate x:Key="ClosableTabItemTemplate">
        <DockPanel Width="120">
            <Button x:Name="PART_Close" Command="{Binding Path=CloseCommand}" 
                    DockPanel.Dock="Right" Style="{DynamicResource CloseButtonStyle}" ToolTip="Close Tab">
            </Button>
            <ContentPresenter Content="{Binding Path=DisplayName}" VerticalAlignment="Center" ToolTip="{Binding Path=DisplayName}" />
        </DockPanel>
    </DataTemplate>

    <!--
  This template explains how to render the 'Workspace' content area in the main window.
  -->
    <DataTemplate x:Key="WorkspacesTemplate">
        <TabControl IsSynchronizedWithCurrentItem="True" 
                    ItemsSource="{Binding}" 
                    ItemTemplate="{StaticResource ClosableTabItemTemplate}"
                    Margin="2"/>

    </DataTemplate>


    <!-- TabItem CloseButton Brush-->
    <SolidColorBrush x:Key="TabCloseButtonBrush" Color="#FFADADAD"/>

    <!-- TabItem Brushes -->
    <SolidColorBrush x:Key="TabItemNormalBackground" Color="WhiteSmoke"/>
    <SolidColorBrush x:Key="TabItemHoverBackground" Color="LightGray"/>
    <SolidColorBrush x:Key="TabItemSelectedBackground" Color="LightGray"/>

    <!-- Style for the Close Button on each TabItem -->
    <Style x:Key="CloseButtonStyle" TargetType="{x:Type Button}">
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border x:Name="border" Background="{TemplateBinding Background}" 
                            BorderThickness="1"  BorderBrush="{TemplateBinding BorderBrush}" 
                            Width="16" Height="16" SnapsToDevicePixels="True">
                        <Grid Width="8" Height="8" HorizontalAlignment="Center" VerticalAlignment="Center">
                            <Path x:Name="path1" Stroke="{StaticResource TabCloseButtonBrush}" Data="M0,0 L8,8" StrokeThickness="2" />
                            <Path x:Name="path2" Stroke="{StaticResource TabCloseButtonBrush}" Data="M8,0 L0,8" StrokeThickness="2" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" Value="{StaticResource TabCloseButtonBrush}"/>
                            <Setter Property="Background" Value="WhiteSmoke"/>
                            <Setter Property="Stroke" TargetName="path1" Value="DarkRed"/>
                            <Setter Property="Stroke" TargetName="path2" Value="DarkRed"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Background">
                                <Setter.Value>
                                    <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                                        <GradientStop Color="#FFADADAD" Offset="0"/>
                                        <GradientStop Color="White" Offset="0.5"/>
                                        <GradientStop Color="White" Offset="1"/>
                                    </LinearGradientBrush>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type TabControl}">
        <Setter Property="BorderBrush" Value="LightGray"/>
        <Setter Property="BorderThickness" Value="0,1,0,0"/>
    </Style>

    <Style TargetType="{x:Type TabItem}">
        <Setter Property="BorderBrush" Value="Gray"/>
        <Setter Property="Padding" Value="0" />
        <Setter Property="HorizontalAlignment" Value="Stretch" />
        <Setter Property="VerticalAlignment" Value="Stretch" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabItem}">
                    <Border x:Name="Bd" BorderThickness="1" Margin="1" CornerRadius="2"
							Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
							SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Grid HorizontalAlignment="Stretch">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>

                            <Border x:Name="tabContent"  Margin="2,0,2,0" Grid.Column="1">
                                <ContentPresenter
									    Content="{TemplateBinding Header}"
									    ContentTemplate="{TemplateBinding HeaderTemplate}"
									    ContentSource="Header"
										HorizontalAlignment="Left"
										VerticalAlignment="Center"
									    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
									    Margin="{TemplateBinding Padding}"
									    RecognizesAccessKey="True"/>
                            </Border>

                            <!--<Button Grid.Column="2" 
							        VerticalAlignment="Center"
							        HorizontalAlignment="Center"
							        Margin="5,0,5,0"
							        Style="{StaticResource CloseButtonStyle}"
							        Visibility="Visible"
                                    Click="CloseButton_Click" />-->
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Background" Value="LightSteelBlue" />
                            <Setter Property="Foreground" Value="Black"/>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter Property="Background" Value="WhiteSmoke" />
                            <Setter Property="Foreground" Value="Black"/>
                            <Setter Property="Margin" TargetName="Bd" Value="0" />
                            <Setter Property="BorderThickness" TargetName="tabContent" Value="2"/>
                            <Setter Property="Margin" TargetName="Bd" Value="0"/>
                            <Setter Property="BorderThickness" TargetName="Bd" Value="1,1,1,0"/>
                            <Setter Property="Padding" TargetName="Bd" Value="3"/>
                            <Setter Property="CornerRadius" TargetName="Bd" Value="4,4,0,0"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- TabItem Style, defines the look of a Tab Item-->
    <Style x:Key="CloseableTab" TargetType="{x:Type TabItem}">
        <Setter Property="BorderBrush" Value="Gray"/>
        <Setter Property="Padding" Value="1" />
        <Setter Property="HorizontalAlignment" Value="Stretch" />
        <Setter Property="VerticalAlignment" Value="Stretch" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabItem}">
                    <Border x:Name="Bd"
							Background="{TemplateBinding Background}"
							BorderBrush="{TemplateBinding BorderBrush}"
							SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Grid HorizontalAlignment="Stretch">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>

                            <Border Margin="2,0,2,0" Grid.Column="1">
                                <ContentPresenter
									    Content="{TemplateBinding Header}"
									    ContentTemplate="{TemplateBinding HeaderTemplate}"
									    ContentSource="Header"
										HorizontalAlignment="Left"
										VerticalAlignment="Center"
									    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
									    Margin="{TemplateBinding Padding}"
									    RecognizesAccessKey="True"/>
                            </Border>

                            <!--<Button x:Name="PART_CloseButton" 
							        Grid.Column="2" 
							        VerticalAlignment="Center"
							        HorizontalAlignment="Center"
							        Margin="5,0,5,0"
							        Style="{StaticResource CloseButtonStyle}"
							        Visibility="Visible"
                                    Click="CloseButton_Click" />-->
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Background" Value="{Binding Path=TabItemMouseOverBackground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabControl}}}" />
                            <Setter Property="Foreground" Value="Black"/>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter Property="Background" Value="{Binding Path=TabItemSelectedBackground, 
                                    RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabControl}}}" />
                            <Setter Property="Foreground" Value="Black"/>
                            <Setter Property="Margin" TargetName="Bd" Value="0"/>
                            <Setter Property="BorderBrush" TargetName="Bd" Value="Gray"/>
                        </Trigger>

                        <Trigger Property="TabStripPlacement" Value="Top">
                            <Setter Property="BorderThickness" TargetName="Bd" Value="1,1,1,0"/>
                            <Setter Property="CornerRadius" TargetName="Bd" Value="4,4,0,0"/>
                            <Setter Property="Margin" TargetName="Bd" Value="0,4,0,0"/>
                        </Trigger>

                        <Trigger Property="TabStripPlacement" Value="Bottom">
                            <Setter Property="BorderThickness" TargetName="Bd" Value="1,0,1,1"/>
                            <Setter Property="CornerRadius" TargetName="Bd" Value="0,0,4,4"/>
                            <Setter Property="Margin" TargetName="Bd" Value="0,-1,0,7"/>
                        </Trigger>

                        <Trigger Property="TabStripPlacement" Value="Left">
                            <Setter Property="BorderThickness" TargetName="Bd" Value="1,1,0,1"/>
                            <Setter Property="CornerRadius" TargetName="Bd" Value="4,0,0,0"/>
                            <Setter Property="Margin" TargetName="Bd" Value="0,0,0,-1"/>
                        </Trigger>

                        <Trigger Property="TabStripPlacement" Value="Right">
                            <Setter Property="BorderThickness" TargetName="Bd" Value="0,1,1,1"/>
                            <Setter Property="CornerRadius" TargetName="Bd" Value="0,4,0,0"/>
                            <Setter Property="Margin" TargetName="Bd" Value="0,0,0,-1"/>
                        </Trigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="TabStripPlacement" Value="Top"/>
                                <Condition Property="IsSelected" Value="true"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Panel.ZIndex" Value="2" />
                            <Setter Property="BorderThickness" TargetName="Bd" Value="1,1,1,0"/>
                            <Setter Property="CornerRadius" TargetName="Bd" Value="4,4,0,0"/>
                            <Setter Property="Margin" TargetName="Bd" Value="0,0,0,-1"/>
                        </MultiTrigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="TabStripPlacement" Value="Bottom"/>
                                <Condition Property="IsSelected" Value="true"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Panel.ZIndex" Value="2" />
                            <Setter Property="BorderThickness" TargetName="Bd" Value="1,0,1,1"/>
                            <Setter Property="CornerRadius" TargetName="Bd" Value="0,0,4,4"/>
                            <Setter Property="Margin" TargetName="Bd" Value="0,-1,0,0"/>
                        </MultiTrigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="TabStripPlacement" Value="Left"/>
                                <Condition Property="IsSelected" Value="true"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Panel.ZIndex" Value="2" />
                            <Setter Property="BorderThickness" TargetName="Bd" Value="1,1,0,1"/>
                            <Setter Property="CornerRadius" TargetName="Bd" Value="4,0,0,4"/>
                            <Setter Property="Margin" TargetName="Bd" Value="0,0,0,-1"/>
                        </MultiTrigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="TabStripPlacement" Value="Right"/>
                                <Condition Property="IsSelected" Value="true"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Panel.ZIndex" Value="2" />
                            <Setter Property="BorderThickness" TargetName="Bd" Value="1,1,1,1"/>
                            <Setter Property="CornerRadius" TargetName="Bd" Value="0,4,0,0"/>
                            <Setter Property="Margin" TargetName="Bd" Value="0,0,0,-1"/>
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <SolidColorBrush x:Key="GlyphBrush" Color="#444" />

</ResourceDictionary>

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
Architect
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions