James Joshua Street
James Joshua Street

Reputation: 3419

WPF where can i find the default style of treeview's togglebuton?

I was following a tutorial on how to modify the controltemplate, but the tutorial overrides the original toggle button with a new togglebutton that uses a Path to draw a triangle, rather than the original crosshair shaped expander. Does the original exist somewhere that I can just reference in a style? or am I going to have to just draw it using a rectangle and paths?

<Style x:Key="ExpandCollapseToggleStyle" TargetType="ToggleButton">
   <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="ToggleButton">
          <Grid
          Width="15"
          Height="13"
          Background="Transparent">
            <Path x:Name="ExpandPath"
            HorizontalAlignment="Left" 
            VerticalAlignment="Center" 
            Margin="1,1,1,1"
            Fill="{StaticResource GlyphBrush}"
            Data="M 4 0 L 8 4 L 4 8 Z"/>
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="IsChecked"
               Value="True">
              <Setter Property="Data"
                TargetName="ExpandPath"
                Value="M 0 4 L 8 4 L 4 8 Z"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

and elsewhere

           <ToggleButton x:Name="Expander"
                  Style="{StaticResource ExpandCollapseToggleStyle}"
                  IsChecked="{Binding Path=IsExpanded,
                              RelativeSource={RelativeSource TemplatedParent}}"
                  ClickMode="Press"/>

Upvotes: 1

Views: 3752

Answers (2)

dnxit
dnxit

Reputation: 7350

You can use Expander control like this.

<Grid>
    <Expander Name="PART_Expander" IsExpanded="{TemplateBinding TreeViewItem.IsExpanded}">
         <Expander.Header>
            <ContentPresenter ContentSource="Header" />
         </Expander.Header>
            <ItemsPresenter />
    </Expander>
    <ContentPresenter Name="PART_ContentPresenter" ContentSource="Header" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Collapsed" />
</Grid>

Upvotes: 0

Athari
Athari

Reputation: 34293

You can find default styles on MSDN.

If you want to reference a style you need to add reference to PresentationFramework.Aero (or any other theme) and merge the resources. However, it breakes theme "magic", so copying the style to your resources is probably a better idea.

Upvotes: 2

Related Questions