Click here to Skip to main content
15,891,513 members
Articles / Desktop Programming / WPF

Composite Application Library in WPF Application

Rate me:
Please Sign up or sign in to vote.
4.82/5 (30 votes)
2 Mar 2009CPOL8 min read 95.7K   3.1K   110  
WPF application built on the Composite Application Library. How to start, organize solution projects, distribute resources and build complex UI using the Presentation Model pattern.
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
   

    <Style x:Key="{x:Type Menu}" TargetType="{x:Type Menu}">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Background" Value="{DynamicResource MenuBackgroundBrush}" />
        <Setter Property="Padding" Value="4,0,0,0" />
    </Style>
    
    <DropShadowBitmapEffect x:Key="ShowDrop" Color="#71000000" Direction="320" ShadowDepth="5" Softness="0.2" Opacity="0.4" />
    <Geometry x:Key="Checkmark">M 0,5.1 L 1.7,5.2 L 3.4,7.1 L 8,0.4 L 9.2,0 L 3.3,10.8 Z</Geometry>

    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}" 
            TargetType="{x:Type ContentControl}">
        <Border Background="#F5F5F5" BorderBrush="#FF959595" BorderThickness="1">
            <Grid>
                <Rectangle Fill="#F1F1F1" RadiusX="2" RadiusY="2" HorizontalAlignment="Left" Margin="2" Width="28"/>
                <Rectangle Fill="#E2E3E3" HorizontalAlignment="Left" Margin="30,2,0,2" Width="1"/>
                <Rectangle Fill="White" HorizontalAlignment="Left" Margin="31,2,0,2" Width="1"/>
                <ContentPresenter Margin="1,0" Grid.ColumnSpan="2"/>
            </Grid>
        </Border>
    </ControlTemplate>
    
    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" 
            TargetType="{x:Type MenuItem}">
        <Grid SnapsToDevicePixels="true">
            <Rectangle x:Name="Bg" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="1" RadiusX="1" RadiusY="1" />
            <DockPanel>
                <ContentPresenter Margin="4,0,6,0" x:Name="Icon" VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Icon"/>
                <Path Fill="{TemplateBinding Foreground}" FlowDirection="LeftToRight" Margin="7,0,0,0" x:Name="GlyphPanel" VerticalAlignment="Center" Visibility="Collapsed" Data="{StaticResource Checkmark}"/>
                <TextBlock x:Name="Tb" Foreground="{DynamicResource MenuHeaderForegroundBrush}">
                    <ContentPresenter Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" RecognizesAccessKey="True"/>
                </TextBlock>
            </DockPanel>
            <Popup x:Name="PART_Popup" AllowsTransparency="true" HorizontalOffset="1" 
                    IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" 
                    Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" 
                    VerticalOffset="-1" Focusable="false">
                <Border Name="PopupBorder" Margin="0,0,10,10" SnapsToDevicePixels="True">
                    <ContentControl x:Name="SubMenuBorder" IsTabStop="false" Template="{DynamicResource {ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                        <ScrollViewer Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}" CanContentScroll="true">
                            <ItemsPresenter Margin="2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                    Grid.IsSharedSizeScope="true" KeyboardNavigation.DirectionalNavigation="Cycle" 
                                    KeyboardNavigation.TabNavigation="Cycle"/>
                        </ScrollViewer>
                    </ContentControl>
                </Border>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsSuspendingPopupAnimation" Value="true">
                <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/>
            </Trigger>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/>
                <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
            </Trigger>
             <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
                <Setter Property="BitmapEffect" TargetName="PopupBorder" Value="{StaticResource ShowDrop}"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="true">
                <Setter Property="Fill" TargetName="Bg" Value="{DynamicResource MenuHeaderBackgroundBrushOver}"/>
                <Setter Property="Foreground" TargetName="Tb" Value="{DynamicResource MenuHeaderForegroundBrushOver}"/>
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="true">
                <Setter Property="Fill" TargetName="Bg" Value="{DynamicResource MenuHeaderBackgroundBrushPressed}"/>
                <Setter Property="Foreground" TargetName="Tb" Value="{DynamicResource MenuHeaderForegroundBrush}"/>
            </Trigger>
            <Trigger Property="IsSubmenuOpen" Value="true">
                <Setter Property="Fill" TargetName="Bg" Value="{DynamicResource MenuHeaderBackgroundBrushPressed}"/>
                <Setter Property="Foreground" TargetName="Tb" Value="{DynamicResource MenuHeaderForegroundBrush}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}"/>
                <Setter Property="Fill" TargetName="GlyphPanel" Value="#848589"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
 
</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
Latvia Latvia
Jevgenij lives in Riga, Latvia. He started his programmer's career in 1983 developing software for radio equipment CAD systems. Created computer graphics for TV. Developed Internet credit card processing systems for banks.
Now he is System Analyst in Accenture.

Comments and Discussions