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

WPF Diagram Designer - Part 4

Rate me:
Please Sign up or sign in to vote.
4.97/5 (243 votes)
26 Mar 2008CPOL6 min read 1.1M   39.6K   515  
A Frankenbuild
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

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

  <!-- SimpleStyles: ToolBarGroupBox -->
  <Style x:Key="ToolbarGroup"  TargetType="GroupBox">
    <Setter Property="Foreground" Value="{DynamicResource ToolbarTextBrush}"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="GroupBox">
          <Grid>
            <Grid.RowDefinitions>
              <RowDefinition Height="*"/>
              <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Rectangle Stroke="GhostWhite" StrokeThickness="1" Margin="1,1,-1,0" RadiusX="3" RadiusY="3" Grid.RowSpan="2"/>
            <Border Grid.Row="0"
                    BorderBrush="{StaticResource ToolbarBorderBrush}"
                    BorderThickness="1,1,1,0"
                    CornerRadius="3,3,0,0" >
              <ContentPresenter Margin="4" />
            </Border>
            <Border Grid.Row="1"
                    Background="{StaticResource ToolbarGroupHeaderBrush}"
                    BorderBrush="{StaticResource ToolbarBorderBrush}"
                    BorderThickness="1,0,1,1"
                    CornerRadius="0,0,3,3" >
              <ContentPresenter HorizontalAlignment="Center"
                                Margin="4"
                                ContentSource="Header"
                                RecognizesAccessKey="True" />
            </Border>

          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- SimpleStyles: ToolBar -->
  <Style x:Key="ToolBarButtonBaseStyle" TargetType="{x:Type ButtonBase}">
    <Setter Property="SnapsToDevicePixels" Value="true"/>
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ButtonBase}">
          <Border
            x:Name="Border"
            BorderThickness="1"
            Background="Transparent"
            BorderBrush="Transparent"
            CornerRadius="3">
            <ContentPresenter
              Margin="{TemplateBinding Padding}"
              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
              RecognizesAccessKey="True"/>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsKeyboardFocused" Value="true">
              <Setter TargetName="Border" Property="Background" Value="{StaticResource ToolbarSelectedBackgroundBrush}" />
              <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource SolidBorderBrush}" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="true">
              <Setter TargetName="Border" Property="Background" Value="{StaticResource ToolbarSelectedBackgroundBrush}" />
              <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource SolidBorderBrush}" />
            </Trigger>
            <Trigger Property="IsPressed" Value="true">
              <Setter TargetName="Border" Property="Background" Value="{StaticResource ToolbarPressedBrush}" />
              <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource PressedBorderBrush}" />
            </Trigger>
            <Trigger Property="CheckBox.IsChecked" Value="true">
              <Setter TargetName="Border" Property="Background" Value="{StaticResource ToolbarPressedBrush}" />
              <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource PressedBorderBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
              <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
              <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
              <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="{x:Static ToolBar.ButtonStyleKey}"
         BasedOn="{StaticResource ToolBarButtonBaseStyle}"
         TargetType="{x:Type Button}"/>
  <Style x:Key="{x:Static ToolBar.ToggleButtonStyleKey}"
         BasedOn="{StaticResource ToolBarButtonBaseStyle}"
         TargetType="{x:Type ToggleButton}"/>
  <Style x:Key="{x:Static ToolBar.CheckBoxStyleKey}"
         BasedOn="{StaticResource ToolBarButtonBaseStyle}"
         TargetType="{x:Type CheckBox}"/>
  <Style x:Key="{x:Static ToolBar.RadioButtonStyleKey}"
         BasedOn="{StaticResource ToolBarButtonBaseStyle}"
         TargetType="{x:Type RadioButton}"/>

  <Style x:Key="{x:Static ToolBar.TextBoxStyleKey}" TargetType="{x:Type TextBox}">
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="AllowDrop" Value="true"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type TextBox}">
          <Border
            Name="Border"
            Padding="2"
            Background="{StaticResource WindowBackgroundBrush}"
            BorderBrush="{StaticResource SolidBorderBrush}"
            BorderThickness="1" >
            <ScrollViewer Margin="0" x:Name="PART_ContentHost"/>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
              <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}"/>
              <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBackgroundBrush}"/>
              <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="ToolBarThumbStyle" TargetType="{x:Type Thumb}">
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="Cursor" Value="SizeAll"/>
    <Setter Property="Visibility" Value="Collapsed"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Thumb}">
          <Border Background="Transparent"
            SnapsToDevicePixels="True">
            <Rectangle Margin="0,2">
              <Rectangle.Fill>
                <DrawingBrush Viewport="0,0,4,4"
                  ViewportUnits="Absolute"
                  Viewbox="0,0,8,8"
                  ViewboxUnits="Absolute"
                  TileMode="Tile">
                  <DrawingBrush.Drawing>
                    <DrawingGroup>
                      <DrawingGroup.Children>
                        <GeometryDrawing Brush="#AAA"
                          Geometry="M 4 4 L 4 8 L 8 8 L 8 4 z"/>
                      </DrawingGroup.Children>
                    </DrawingGroup>
                  </DrawingBrush.Drawing>
                </DrawingBrush>
              </Rectangle.Fill>
            </Rectangle>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="ToolBarOverflowButtonStyle" TargetType="{x:Type ToggleButton}">
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ToggleButton}">
          <Border Name="Bd"
            CornerRadius="0,3,3,0"
            Background="Transparent"
            SnapsToDevicePixels="true">
            <Grid>
              <Path Name="Arrow"
                Fill="Black"
                VerticalAlignment="Bottom"
                Margin="2,3"
                Data="M -0.5 3 L 5.5 3 L 2.5 6 Z"/>
              <ContentPresenter/>
            </Grid>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="true">
              <Setter TargetName="Bd" Property="Background" Value="{StaticResource ToolbarBrush}"/>
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="true">
              <Setter TargetName="Bd" Property="Background" Value="{StaticResource ToolbarBrush}"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
              <Setter TargetName="Bd" Property="Background" Value="{StaticResource ToolbarBrush}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
              <Setter TargetName="Arrow" Property="Fill" Value="#AAA"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type ToolBar}">
    <Setter Property="SnapsToDevicePixels" Value="true"/>
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ToolBar}">
          <Border x:Name="Border"
            CornerRadius="2"
            BorderThickness="1"
            Background="{StaticResource ToolbarBrush}"
            BorderBrush="{StaticResource ToolbarDarkBorderBrush}">
            <DockPanel >
              <ToggleButton DockPanel.Dock="Right"
                IsEnabled="{TemplateBinding HasOverflowItems}"
                Style="{StaticResource ToolBarOverflowButtonStyle}"
                IsChecked="{Binding Path=IsOverflowOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                ClickMode="Press">
                <Popup x:Name="OverflowPopup"
                  AllowsTransparency="true"
                  Placement="Bottom"
                  IsOpen="{Binding Path=IsOverflowOpen,RelativeSource={RelativeSource TemplatedParent}}"
                  StaysOpen="false"
                  Focusable="false"
                  PopupAnimation="Slide">
                  <Border x:Name="DropDownBorder"
                    Background="{StaticResource ToolbarBrush}"
                    BorderThickness="1"
                    BorderBrush="{StaticResource SolidBorderBrush}">
                    <ToolBarOverflowPanel x:Name="PART_ToolBarOverflowPanel"
                      Margin="2"
                      WrapWidth="200"
                      Focusable="true"
                      FocusVisualStyle="{x:Null}"
                      KeyboardNavigation.TabNavigation="Cycle"
                      KeyboardNavigation.DirectionalNavigation="Cycle"/>
                  </Border>
                </Popup>
              </ToggleButton>

              <Thumb x:Name="ToolBarThumb"
                Style="{StaticResource ToolBarThumbStyle}"
                Width="10"/>
              <ToolBarPanel x:Name="PART_ToolBarPanel"
                IsItemsHost="true"
                Margin="0,1,2,2"/>
            </DockPanel>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsOverflowOpen" Value="true">
              <Setter TargetName="ToolBarThumb" Property="IsEnabled" Value="false"/>
            </Trigger>
            <Trigger Property="ToolBarTray.IsLocked" Value="true">
              <Setter TargetName="ToolBarThumb" Property="Visibility" Value="Collapsed"/>
            </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