首页 > 其他分享 >wpf ToggleButton选中效果

wpf ToggleButton选中效果

时间:2024-09-25 16:25:44浏览次数:1  
标签:选中 wpf ToggleButton 效果 先看

先看效果

 

 <Style   TargetType="{x:Type ToggleButton}"> 
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderBrush" Value="DarkGray"/> 
        <Setter Property="BorderThickness" Value="1"/> 
        <Setter Property="Padding" Value="0"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Grid>
                        <Border x:Name="brdOut1"  BorderBrush="{StaticResource MaterialDesignGroupBorder}" Width="20" Height="20" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                        <Border x:Name="brdOut2" BorderBrush="{StaticResource MaterialDesignGroupBorder}" Width="20" Height="20" HorizontalAlignment="Right" VerticalAlignment="Top"/>
                        <Border x:Name="brdOut3" BorderBrush="{StaticResource MaterialDesignGroupBorder}" Width="20" Height="20" HorizontalAlignment="Left" VerticalAlignment="Bottom"/>
                        <Border x:Name="brdOut4" BorderBrush="{StaticResource MaterialDesignGroupBorder}" Width="20" Height="20" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
 
                        <Border Margin="2" x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="0" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">

                          <ContentPresenter Grid.Row="1" x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
                         </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                       
                        <Trigger Property="IsChecked" Value="True">
                            <Setter Property="BorderThickness" TargetName="brdOut1" Value="2,2,0,0"/>
                            <Setter Property="BorderThickness" TargetName="brdOut2" Value="0 2 2 0"/>
                            <Setter Property="BorderThickness" TargetName="brdOut3" Value="2 0 0 2"/>
                            <Setter Property="BorderThickness" TargetName="brdOut4" Value="0 0 2 2"/>

                        </Trigger>
                       
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

 

标签:选中,wpf,ToggleButton,效果,先看
From: https://www.cnblogs.com/czly/p/18431575

相关文章

  • C# + WPF 音频播放器 界面优雅,体验良好
    C#+WPF音频播放器界面优雅,体验良好 合集-.NET开源工具(18)  阅读目录前言项目介绍项目页面项目源码项目地址最后前言本文介绍一款使用C#与WPF开发的音频播放器,其界面简洁大方,操作体验流畅。该播放器支持多种音频格式(如MP4、WMA、OGG、FLAC......
  • .NET 6.0 + WPF 使用 Prism 框架实现导航
    .NET6.0+WPF使用Prism框架实现导航 合集-.NET基础知识(4) 1..NET9优化,抢先体验C#13新特性08-202.《黑神话:悟空》神话再现,虚幻引擎与Unity/C#谁更强?08-213..NET6.0+WPF使用Prism框架实现导航09-114.2024年C#高效开发:精选实用类库09-23收起 ......
  • WPF中控件拖放(二)——拖放示例
    1.创建拖放对象1.1创建一个圆自定义控件,UI代码如下(Circle.xaml):<UserControlx:Class="WpfApp1.Circle"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006......
  • WPF embed C# code into xaml
    <Windowx:Class="WpfApp412.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • WPF Textblock Run glyphFontSize TextDecorations
    <Windowx:Class="WpfApp412.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • WPF Image show picture in high resolution periodically via System.Timers.Timer
    <Windowx:Class="WpfApp411.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • 望繁信科技入选中国信通院“铸基计划”,流程智能引领企业数字化变革
    近日,上海望繁信科技有限公司(以下简称“望繁信科技”)的数字北极星流程智能管理平台,在中国信息通信研究院(以下简称“信通院”)的评选中,荣获2024年度数据治理技术解决方案奖项,并入选《高质量数字化转型产品及服务全景图》。同时,望繁信科技的数字北极星平台成功首批入驻信通院铸基计划应......
  • WPF Image automatically display image via System.Timers.Timer ,pause and resume,
    <Windowx:Class="WpfApp408.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • WPF window fill the full screen and overlap on the taskbar
    WindowState="Maximized"WindowStyle="None"   <Windowx:Class="WpfApp409.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsof......
  • WPF Calendar and DatePicker
    <Windowx:Class="WpfApp407.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......