C#純技術——GroupBox自定義Style

So Long Time Not Write Essay  Hope My Fans Don't Leave Me 🤭

 今天給大家帶來一款自己寫的GrouBox希望我的粉絲們喜歡!

   <UserControl.Resources>
        <!--自定義的GroupBox-->
        <Style   TargetType="GroupBox">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type GroupBox}">
                        <Grid>
                            <Grid  VerticalAlignment="Top">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition/>
                                </Grid.RowDefinitions>

                                <Rectangle Width="160" Height="30"  HorizontalAlignment="Center"  Grid.Row="0" Margin="0" RadiusX="6" RadiusY="6">
                                    <Rectangle.Fill>
                                        <LinearGradientBrush>
                                            <LinearGradientBrush.GradientStops>
                                                <GradientStop Offset="0" Color="#FFD670D3"/>
                                                <GradientStop Offset="0.6" Color="#FF35FDFA"/>
                                            </LinearGradientBrush.GradientStops>
                                        </LinearGradientBrush>
                                    </Rectangle.Fill>
                                </Rectangle>
                                <ContentPresenter Margin="0,8,0,0" ContentSource="Header" RecognizesAccessKey="True" HorizontalAlignment="Center" />

                            </Grid>
                            <Border />
                            <Border CornerRadius="6"  BorderThickness="1"  Margin="10,38,10,10" Background="White" Grid.Row="1">
                                <Border.BorderBrush>
                                    <LinearGradientBrush>
                                        <LinearGradientBrush.GradientStops>
                                            <GradientStop Offset="1" Color="#FF35FDFA"/>
                                            <GradientStop Offset="0.5" Color="#FFD670D3"/>
                                        </LinearGradientBrush.GradientStops>
                                    </LinearGradientBrush>
                                </Border.BorderBrush>
                                <ContentPresenter Margin="5"/>
                            </Border>

                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <!--自定義的ToggleButton-->
        <Style TargetType="ToggleButton">
            <Setter Property="Background" Value="Transparent"/>
            <!--聲明所需要用到的顏色-->
            <Setter Property="HorizontalAlignment" Value="Center"/>
            <!--聲明所需要用到的  水平排列方式-->
            <Setter Property="VerticalAlignment" Value="Center"/>
            <!--聲明所需要用到的  垂直排列方式-->
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <!--聲明所需要用到的  內容水平排列方式-->
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <!--聲明所需要用到的  內容垂直排列方式-->
            <Setter Property="Padding" Value="0"/>
            <!--偏移值-->
            <Setter Property="BorderThickness" Value="0"/>
            <!--邊框-->
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Rectangle x:Name="RecFill" Width="12" Height="12" RadiusX="12" RadiusY="12" Fill="Transparent"   Stroke="BlueViolet"  StrokeThickness="0.8"  >
                        </Rectangle>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Opacity" Value="0.8"/>
                            </Trigger>
                            <Trigger Property="ToggleButton.IsChecked" Value="true">
                                <Setter Property="Fill" TargetName="RecFill" Value="BlueViolet"/>
                            </Trigger>
                            <Trigger Property="ToggleButton.IsChecked" Value="false">
                                <Setter Property="Fill" TargetName="RecFill" Value="Transparent"/>
                            </Trigger>

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

    </UserControl.Resources>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章