WPF Expander button style with + and -

后端 未结 1 1722
情书的邮戳
情书的邮戳 2021-01-03 12:31

Styling gurus, I need help coming up with an Expander style that looks like the one found in Visual Studio\'s code editor. So far, I have come up with this

         


        
相关标签:
1条回答
  • 2021-01-03 12:53

    Here is a style I use.

    <Style x:Key="ExpandCollapseToggleStyle" TargetType="ToggleButton">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ToggleButton">
                    <Grid Width="14" Height="14">
                        <Rectangle Fill="{DynamicResource primaryBackgroundBrush}" />
                        <Border Name="ExpandBorder" RenderOptions.EdgeMode="Aliased" BorderBrush="Black" BorderThickness="2">
                            <Path RenderOptions.EdgeMode="Aliased" Name="ExpandPath" Stroke="Black" Margin="0" StrokeThickness="2" Data="M 5 1 L 5 9 M 1 5 L 9 5" />
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter Property="Data" TargetName="ExpandPath" Value="M 1 5 L 9 5"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="ExpandBorder" Property="BorderBrush" Value="Gray" />
                            <Setter TargetName="ExpandPath" Property="Stroke" Value="Gray" />
                            <Setter Property="Data" TargetName="ExpandPath" Value=""/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    0 讨论(0)
提交回复
热议问题