Click here to Skip to main content
12,360,217 members (62,051 online)
Click here to Skip to main content

Stats

236.8K views
16.1K downloads
310 bookmarked
Posted

WPF Diagram Designer - Part 2

, 8 Oct 2008 CPOL
Designer Canvas with Zoombox
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Brushes.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="ToggleButtonStyle"
           TargetType="ToggleButton">
        <Setter Property="SnapsToDevicePixels"
                Value="true" />
        <Setter Property="OverridesDefaultStyle"
                Value="true" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ToggleButton">
                    <Border x:Name="Border"
                            CornerRadius="2"
                            BorderThickness="1"
                            Background="{StaticResource NormalBrush}"
                            BorderBrush="{StaticResource NormalBorderBrush}">
                        <ContentPresenter Margin="{TemplateBinding Padding}"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver"
                                 Value="true">
                            <Setter TargetName="Border"
                                    Property="Background"
                                    Value="{StaticResource DarkBrush}" />
                        </Trigger>
                        <Trigger Property="IsPressed"
                                 Value="true">
                            <Setter TargetName="Border"
                                    Property="Background"
                                    Value="{StaticResource PressedBrush}" />
                            <Setter TargetName="Border"
                                    Property="BorderBrush"
                                    Value="{StaticResource PressedBorderBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="Expander">
        <Setter Property="Padding"
                Value="8" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Expander">
                    <DockPanel>
                        <ToggleButton Style="{StaticResource ToggleButtonStyle}"
                                      DockPanel.Dock="Top"
                                      IsChecked="{Binding Path=IsExpanded,Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                      HorizontalContentAlignment="Left"
                                      VerticalContentAlignment="Center">
                            <ToggleButton.Content>
                                <StackPanel Orientation="Horizontal">
                                    <Path SnapsToDevicePixels="True"
                                          Name="Arrow"
                                          Margin="8,0,8,0"
                                          Fill="{TemplateBinding Foreground}"
                                          Stroke="{TemplateBinding Foreground}"
                                          StrokeThickness="0.5"
                                          RenderTransformOrigin="0.5,0.5"
                                          HorizontalAlignment="Right"
                                          VerticalAlignment="Center"
                                          Data="M 0 0 L 0 8 L 5 4 Z">
                                        <Path.RenderTransform>
                                            <RotateTransform Angle="0" />
                                        </Path.RenderTransform>
                                    </Path>
                                    <ContentPresenter Name="HeaderContent"
                                                      Margin="4"
                                                      ContentSource="Header" />
                                </StackPanel>
                            </ToggleButton.Content>
                        </ToggleButton>
                        <Border Name="Content"
                                BorderThickness="1,0,1,1"
                                BorderBrush="{StaticResource NormalBorderBrush}"
                                Background="{TemplateBinding Background}"
                                CornerRadius="0,0,1,1"
                                SnapsToDevicePixels="True">
                            <Border.LayoutTransform>
                                <ScaleTransform ScaleY="0" />
                            </Border.LayoutTransform>
                            <ContentPresenter Content="{TemplateBinding Content}"
                                              ToolTipService.IsEnabled="False" />
                        </Border>
                    </DockPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Expander.IsExpanded"
                                 Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="Content"
                                                         Storyboard.TargetProperty="LayoutTransform.ScaleY"
                                                         To="1"
                                                         Duration="0:0:0.5" />
                                        <DoubleAnimation Storyboard.TargetName="Content"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To="1"
                                                         Duration="0:0:0.5" />
                                        <DoubleAnimation Storyboard.TargetName="Arrow"
                                                         Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(RotateTransform.Angle)"
                                                         Duration="0:0:0.2"
                                                         To="90"
                                                         DecelerationRatio="1" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="Content"
                                                         Storyboard.TargetProperty="LayoutTransform.ScaleY"
                                                         To="0"
                                                         Duration="0:0:0.5" />
                                        <DoubleAnimation Storyboard.TargetName="Content"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To="0"
                                                         Duration="0:0:0.5" />
                                        <DoubleAnimation Storyboard.TargetName="Arrow"
                                                         Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(RotateTransform.Angle)"
                                                         Duration="0:0:0.2"
                                                         AccelerationRatio="1" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</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)

Share

About the Author

sukram
Austria Austria
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 8 Oct 2008
Article Copyright 2008 by sukram
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid