• wpf -----Expander自定义样式


    Expander是一个可以展开和折叠的控件,由ContentPresenter和ToggleButton组成

    <!--Expander样式-->
    <Style x:Key="ExpanderStyle" TargetType="{x:Type Expander}">
    <Setter Property="Foreground" Value="Black"/>
    <Setter Property="FontFamily" Value="宋体" />
    <Setter Property="FontSize" Value="12" />
    <Setter Property="Background" Value="#ffffff"/>
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    <Setter Property="VerticalContentAlignment" Value="Stretch"/>
    <Setter Property="BorderBrush" Value="Transparent"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="Width" Value="276"/>
    <Setter Property="Template">
    <Setter.Value>
    <ControlTemplate TargetType="{x:Type Expander}">
    <Canvas Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
    <ToggleButton x:Name="HeaderSite" 
    Canvas.Top="0"
    ContentTemplate="{TemplateBinding HeaderTemplate}" 
    ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
    Content="{TemplateBinding Header}" 
    IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" 
    Style="{DynamicResource ToggleButtonStyle}" />
    <Border x:Name="ExpandSite" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
    VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
    Visibility="Collapsed" 
    
    
    Canvas.Top="0" Canvas.Left="0"
    
    
    Focusable="false"
    BorderBrush="{TemplateBinding BorderBrush}"
    BorderThickness="{TemplateBinding BorderThickness}" 
    Background="#ffffff" ScrollViewer.VerticalScrollBarVisibility="Hidden">
    <ContentPresenter Margin="10 0" 
    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
    VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
    </Border>
    
    </Canvas>
    <ControlTemplate.Triggers>
    <Trigger Property="IsExpanded" Value="true">
    <Setter Property="Visibility" TargetName="ExpandSite" Value="Visible"/>
    </Trigger>
    <Trigger Property="IsEnabled" Value="false">
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
    </Trigger>
    </ControlTemplate.Triggers>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>
    
     

    <!--ToggleButton样式-->

    <!--ToggleButton样式-->
    
    <Style x:Key="ToggleButtonStyle" TargetType="{x:Type ToggleButton}">
    
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="Width" Value="275"/>
    <Setter Property="Height" Value="25" />
    
    <Setter Property="Background" Value="#ffffff" />
    
    <Setter Property="Foreground" Value="#FF217c"/>
    <Setter Property="FontSize" Value="12" />
    <Setter Property="FontFamily" Value="宋体" />
    <Setter Property="FontWeight" Value="Bold" />
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="HorizontalContentAlignment" Value="Left"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="Padding" Value="10 5"/>
    <Setter Property="Template">
    <Setter.Value>
    <ControlTemplate TargetType="{x:Type ToggleButton}">
    <Canvas Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" 
    Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
    <Canvas x:Name="canvNormal" Visibility="Visible" 
    Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" 
    Background="{TemplateBinding Background}" SnapsToDevicePixels="True" Canvas.Right="0">
    <Rectangle Width="275" Height="35" Fill="Red" Canvas.Right="0"/>
    <Path Data="M 0 0 L 6 -6 12 0 " Stroke="#7D7D7D" StrokeThickness="2" Canvas.Right="5" Canvas.Top="18"/>
    <!--<Rectangle Width="{TemplateBinding Width}" Height="1" Canvas.Bottom="0" Fill="#E3E3E3" />-->
    </Canvas>
    <Canvas x:Name="canvChecked" Visibility="Hidden" 
    Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" 
    Background="{TemplateBinding Background}" SnapsToDevicePixels="True" Canvas.Right="0">
    <Path Data="M 0 0 L 6 6 12 0 " Stroke="#7D7D7D" StrokeThickness="2" Canvas.Right="5" Canvas.Top="10"/>
    <Rectangle Width="{TemplateBinding Width}" Height="1" Canvas.Bottom="0" Fill="#E3E3E3" />
    </Canvas>
    
    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
    Margin="{TemplateBinding Padding}" 
    RecognizesAccessKey="True" 
    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
    </Canvas>
    
    <ControlTemplate.Triggers>
    <Trigger Property="IsPressed" Value="true">
    <!--点击颜色-->
    <Setter Property="Background" Value="Red"/>
    </Trigger>
    <Trigger Property="IsChecked" Value="true">
    <Setter Property="Visibility" TargetName="canvChecked" Value="Visible" />
    <Setter Property="Visibility" TargetName="canvNormal" Value="Hidden" />
    </Trigger>
    <Trigger Property="IsEnabled" Value="false">
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
    </Trigger>
    
    </ControlTemplate.Triggers>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>

    主程序代码:

    <Expander ExpandDirection="Down " Width="276"
    HorizontalAlignment="Left" IsExpanded="true" 
    Style="{DynamicResource ExpanderStyle}" Height="24" VerticalAlignment="Bottom" >
    <Expander.Header>
    <TextBlock Text="2.分析图" Name="abc" PreviewMouseLeftButtonDown="CloseClick"/>
    </Expander.Header>
    <!--<Expander.Content>
    <TextBlock Text="文本内容" TextWrapping="Wrap" Name="asdf" />
    </Expander.Content>-->
    </Expander>

     参考的链接为:https://blog.csdn.net/Qiustion/article/details/24377555

  • 相关阅读:
    自动化测试过程中所入的坑3——解决问题思维的转换
    自动化测试所入的坑2
    js原生触发angular事件
    Selenium2Library源码中browser的传递
    Selenium自动化测试中的等待
    Android adb 命令学习笔记
    Robot学习笔记
    Xpath 与Css 定位方式的比较
    Selenium填坑笔记
    python批量更改文件名
  • 原文地址:https://www.cnblogs.com/lovebear123/p/11598977.html
Copyright © 2020-2023  润新知