编程语言
首页 > 编程语言> > C#——滑动开关按钮

C#——滑动开关按钮

作者:互联网

先上效果图

 

 .xaml文件中加入:

    <Window.Resources>
        <ResourceDictionary>
            <Style x:Key="ToggleButtonStyle" TargetType="{x:Type ToggleButton}">
                <Setter Property="Width" Value="45"></Setter>
                <Setter Property="Height" Value="20"></Setter>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ToggleButton">
                            <!--定义视觉树-->
                            <Border x:Name="border" BorderThickness="1.5" CornerRadius="9" BorderBrush="#aaa" Background="#2790ff">
                                <Grid x:Name="togglebutton" HorizontalAlignment="Right" >
                                    <Border Width="17" Height="17" CornerRadius="9" Background="White"/>
                                </Grid>
                                <!--阴影设置-->
                                <Border.Effect>
                                    <DropShadowEffect Color="Gray" BlurRadius="5" ShadowDepth="0" Opacity="0.5" />
                                </Border.Effect>
                            </Border>
                            <!--定义触发器-->
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsChecked" Value="false">
                                    <Setter TargetName="border" Property="Background" Value="#ccc"/>
                                    <Setter TargetName="togglebutton" Property="HorizontalAlignment" Value="Left"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </Window.Resources>

使用的时候:

        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="20,10,0,0" Grid.Column="1" Width="160">
            <Label Content="*****" Width="53"/>
            <TextBlock Text="{Binding ToggleStatus}" Margin="10 0 0 0"/>
            <ToggleButton x:Name="*****" Style="{StaticResource ToggleButtonStyle}" IsChecked="{Binding ToggleBtnIsCheck}" Checked="ToggleButton_Checked" Unchecked="ToggleButton_Unchecked"/>
        </StackPanel>

做了好久的用户控件和自定控件,但导入dll之后从工具箱里拖出来的控件是空的,没有内容

标签:控件,自定,C#,xaml,dll,按钮,滑动,工具箱
来源: https://www.cnblogs.com/junk-code-of-bo/p/16316282.html