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

WPF Diagram Designer - Part 2

Rate me:
Please Sign up or sign in to vote.
4.97/5 (147 votes)
8 Oct 2008CPOL5 min read 373.9K   22.3K   342  
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)


Written By
Austria Austria
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions