Click here to Skip to main content
12,353,607 members (69,045 online)
Click here to Skip to main content

Stats

236.5K 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"
  xmlns:sys="clr-namespace:System;assembly=mscorlib" >

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Brushes.xaml" />
  </ResourceDictionary.MergedDictionaries>
  
  <Style x:Key="ToolBarButtonBaseStyle" TargetType="{x:Type ButtonBase}">
    <Setter Property="SnapsToDevicePixels" Value="true"/>
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ButtonBase}">
          <Border 
            x:Name="Border"  
            BorderThickness="1"
            Background="Transparent"
            BorderBrush="Transparent">
            <ContentPresenter 
              Margin="2"
              HorizontalAlignment="Center"
              VerticalAlignment="Center"
              RecognizesAccessKey="True"/>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsKeyboardFocused" Value="true">
              <Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}" />
              <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource SolidBorderBrush}" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="true">
              <Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}" />
              <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource SolidBorderBrush}" />
            </Trigger>
            <Trigger Property="IsPressed" Value="true">
              <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBrush}" />
              <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource PressedBorderBrush}" />
            </Trigger>
            <Trigger Property="CheckBox.IsChecked" Value="true">
              <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBrush}" />
              <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="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 DarkBrush}"/>
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="true">
              <Setter TargetName="Bd" Property="Background" Value="{StaticResource DarkBrush}"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
              <Setter TargetName="Bd" Property="Background" Value="{StaticResource DarkBrush}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
              <Setter TargetName="Arrow" Property="Fill" Value="#AAA"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="{x:Type ToolBar}" TargetType="{x:Type ToolBar}">
    <Setter Property="SnapsToDevicePixels" Value="true"/>
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="OverflowMode" Value="Never"/>
    <Setter Property="ToolBarTray.IsLocked" Value="True"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ToolBar}">
          <Border x:Name="Border"  
            CornerRadius="1" 
            BorderThickness="1"
            Background="{StaticResource NormalBrush}"
            BorderBrush="Gray">
            <DockPanel >                            
              <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>

  <Style x:Key="{x:Type ToolBarTray}" TargetType="{x:Type ToolBarTray}" >
    <Setter Property="Background" Value="{StaticResource HorizontalLightBrush}"/>
  </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