Skip to content

Commit

Permalink
feat: 添加了 GroupBox
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimeNull committed May 22, 2024
1 parent 097e27f commit c4f7e9a
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
23 changes: 23 additions & 0 deletions EleCho.WpfSuite/Controls/GroupBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Windows;

namespace EleCho.WpfSuite
{
public class GroupBox : System.Windows.Controls.GroupBox
{
static GroupBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(GroupBox), new FrameworkPropertyMetadata(typeof(GroupBox)));
}


public CornerRadius CornerRadius
{
get { return (CornerRadius)GetValue(CornerRadiusProperty); }
set { SetValue(CornerRadiusProperty, value); }
}


public static readonly DependencyProperty CornerRadiusProperty =
Border.CornerRadiusProperty.AddOwner(typeof(GroupBox), new FrameworkPropertyMetadata(new CornerRadius(3)));
}
}
45 changes: 45 additions & 0 deletions EleCho.WpfSuite/Controls/GroupBoxResources.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ws="https://github.com/OrgEleCho/EleCho.WpfSuite">
<BorderGapMaskConverter x:Key="BorderGapMaskConverter"/>
<Style TargetType="{x:Type ws:GroupBox}">
<Setter Property="BorderBrush" Value="#D5DFE5"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ws:GroupBox}">
<Grid SnapsToDevicePixels="true">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="6"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="6"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="6"/>
</Grid.RowDefinitions>
<Border Background="{TemplateBinding Background}" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4" Grid.Column="0" Grid.ColumnSpan="4" Grid.RowSpan="3" Grid.Row="1"/>
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}" Grid.ColumnSpan="4" Grid.RowSpan="3" Grid.Row="1">
<Border.OpacityMask>
<MultiBinding ConverterParameter="7" Converter="{StaticResource BorderGapMaskConverter}">
<Binding ElementName="Header" Path="ActualWidth"/>
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Mode=Self}"/>
<Binding Path="ActualHeight" RelativeSource="{RelativeSource Mode=Self}"/>
</MultiBinding>
</Border.OpacityMask>
</Border>
<Border x:Name="Header" Grid.Column="1" Padding="3,1,3,0" Grid.RowSpan="2" Grid.Row="0">
<ContentPresenter ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<ContentPresenter Grid.Column="1" Grid.ColumnSpan="2" Margin="{TemplateBinding Padding}" Grid.Row="2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
2 changes: 2 additions & 0 deletions EleCho.WpfSuite/EleCho.WpfSuite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<Page Remove="Controls\ComboBoxResources.xaml" />
<Page Remove="Controls\ConditionalControlResources.xaml" />
<Page Remove="Controls\FrameResources.xaml" />
<Page Remove="Controls\GroupBoxResources.xaml" />
<Page Remove="Controls\ImageResources.xaml" />
<Page Remove="Controls\ListBoxItemResources.xaml" />
<Page Remove="Controls\ListBoxResources.xaml" />
Expand Down Expand Up @@ -58,6 +59,7 @@
<Resource Include="Controls\ComboBoxItemResources.xaml" />
<Resource Include="Controls\ComboBoxResources.xaml" />
<Resource Include="Controls\FrameResources.xaml" />
<Resource Include="Controls\GroupBoxResources.xaml" />
<Resource Include="Controls\ListBoxItemResources.xaml" />
<Resource Include="Controls\ListBoxResources.xaml" />
<Resource Include="Controls\ProgressBarResources.xaml" />
Expand Down
1 change: 1 addition & 0 deletions EleCho.WpfSuite/Themes/Generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
<ResourceDictionary Source="pack://application:,,,/EleCho.WpfSuite;component/Controls/ListBoxResources.xaml"/>
<ResourceDictionary Source="pack://application:,,,/EleCho.WpfSuite;component/Controls/ListBoxItemResources.xaml"/>
<ResourceDictionary Source="pack://application:,,,/EleCho.WpfSuite;component/Controls/ProgressBarResources.xaml"/>
<ResourceDictionary Source="pack://application:,,,/EleCho.WpfSuite;component/Controls/GroupBoxResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
6 changes: 3 additions & 3 deletions WpfTest/Tests/PanelsTestPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<TextBlock Text="Panels Test"
FontSize="26"
Margin="0 0 0 12"/>
<GroupBox Header="StackPanel (Spacing=8)"
Padding="8">
<ws:GroupBox Header="StackPanel (Spacing=8)"
Padding="8">
<ws:StackPanel Orientation="Horizontal"
Spacing="8">
<i:Interaction.Behaviors>
Expand All @@ -30,7 +30,7 @@
<ws:Button Content="QWQ"/>
<ws:Button Content="QWQ"/>
</ws:StackPanel>
</GroupBox>
</ws:GroupBox>
<GroupBox Header="WrapPanel (HorizontalSpacing=8,VerticalSpacing=8)"
Padding="8">
<ws:WrapPanel Orientation="Horizontal"
Expand Down

0 comments on commit c4f7e9a

Please sign in to comment.