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

WPF Diagram Designer - Part 3

Rate me:
Please Sign up or sign in to vote.
4.96/5 (245 votes)
29 Feb 2008CPOL4 min read 668.8K   22.8K   571  
Connecting items
<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: Expander -->

  <ControlTemplate x:Key="ExpanderToggleButton" TargetType="ToggleButton">
    <Border
      Name="Border" 
      CornerRadius="2,0,0,0"
      Background="Transparent"
      BorderBrush="{StaticResource NormalBorderBrush}"
      BorderThickness="0,0,0,0">
      <Path 
        Name="Arrow"
        Fill="{StaticResource GlyphBrush}"
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        Data="M 0 0 L 4 4 L 8 0 Z"/>
    </Border>
    <ControlTemplate.Triggers>
      <Trigger Property="ToggleButton.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}" />
      </Trigger>
      <Trigger Property="IsChecked" Value="true">
        <Setter TargetName="Arrow" Property="Data"
                Value="M 0 4 L 4 0 L 8 4 Z" />
      </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}"/>
        <Setter TargetName="Arrow" Property="Fill"
                Value="{StaticResource DisabledForegroundBrush}" />
      </Trigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>

  <Style TargetType="Expander">
    <Setter Property="FontFamily" Value="SegoeUI"/>
    <Setter Property="FontSize" Value="12"/>
    <Setter Property="Foreground" Value="#4C4C4C"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="Expander">
          <Grid>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto"/>
              <RowDefinition Name="ContentRow" Height="0"/>
            </Grid.RowDefinitions>
            <Border 
              Name="Border" 
              Grid.Row="0" 
              Background="{StaticResource LightBrush}"
              BorderBrush="{StaticResource NormalBorderBrush}"
              BorderThickness="1" 
              CornerRadius="2,2,0,0" >
              <Grid>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="20" />
                  <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <ToggleButton
                  IsChecked="{Binding Path=IsExpanded,Mode=TwoWay,
                                      RelativeSource={RelativeSource TemplatedParent}}"
                  OverridesDefaultStyle="True" 
                  Template="{StaticResource ExpanderToggleButton}" 
                  Background="{StaticResource NormalBrush}" />
                <ContentPresenter 
                  Grid.Column="1"
                  Margin="4" 
                  ContentSource="Header" 
                  RecognizesAccessKey="True" />
              </Grid>
            </Border>
            <Border 
              Name="Content" 
              Grid.Row="1" 
              Background="{StaticResource WindowBackgroundBrush}"
              BorderBrush="{StaticResource SolidBorderBrush}" 
              BorderThickness="1,0,1,1" 
              CornerRadius="0,0,2,2" >
              <ContentPresenter Margin="4" />
            </Border>
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="IsExpanded" Value="True">
              <Setter TargetName="ContentRow" Property="Height"
                      Value="{Binding ElementName=Content,Path=DesiredHeight}" />
            </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>
</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