add SimplePanel

This commit is contained in:
NaBian committed 2019-03-05 23:59:20 +08:00
1 parent be984b1668
commit 785b2f25f5
5 files changed
+44 -10

No files matched your search

-5
View File
@@ -6,11 +6,6 @@ namespace HandyControl.Controls
{
public class Badge : ContentControl
{
public Badge()
{
}
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
"Text", typeof(string), typeof(Badge), new PropertyMetadata(default(string)));
@@ -0,0 +1,38 @@
using System;
using System.Windows;
using System.Windows.Controls;
namespace HandyControl.Controls
{
public class SimplePanel : Panel
{
protected override Size MeasureOverride(Size availableSize)
{
var maxSize = new Size();
var children = InternalChildren;
for (int i = 0, count = children.Count; i < count; ++i)
{
var child = children[i];
if (child != null)
{
child.Measure(availableSize);
maxSize.Width = Math.Max(maxSize.Width, child.DesiredSize.Width);
maxSize.Height = Math.Max(maxSize.Height, child.DesiredSize.Height);
}
}
return maxSize;
}
protected override Size ArrangeOverride(Size arrangeSize)
{
foreach (UIElement child in InternalChildren)
{
child?.Arrange(new Rect(arrangeSize));
}
return arrangeSize;
}
}
}
+1
View File
@@ -116,6 +116,7 @@
<Compile Include="Controls\Other\Dialog.cs" />
<Compile Include="Controls\Other\GotoTop.cs" />
<Compile Include="Controls\Other\Gravatar.cs" />
<Compile Include="Controls\Panel\SimplePanel.cs" />
<Compile Include="Controls\Transfer\Transfer.cs" />
<Compile Include="Controls\Transfer\TransferGroup.cs" />
<Compile Include="Controls\Transfer\TransferItem.cs" />
@@ -15,12 +15,12 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:Badge">
<Grid>
<controls:SimplePanel>
<ContentPresenter/>
<Border HorizontalAlignment="Right" VerticalAlignment="Top" Style="{StaticResource BorderCircular}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<Border Margin="0,-10,-20,0" HorizontalAlignment="Right" VerticalAlignment="Top" Style="{StaticResource BorderCircular}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter ContentSource="Text" Margin="{TemplateBinding Padding}"/>
</Border>
</Grid>
</controls:SimplePanel>
</ControlTemplate>
</Setter.Value>
</Setter>
@@ -5,10 +5,10 @@
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
Background="{DynamicResource RegionBrush}">
<StackPanel Margin="32" Orientation="Horizontal">
<controls:Badge Value="99">
<controls:Badge Value="99" Height="30">
<Button Content="{x:Static langs:Lang.Comment}"/>
</controls:Badge>
<controls:Badge Value="99" Margin="16,0,0,0" Style="{StaticResource BadgeChromeDanger}">
<controls:Badge Value="99" Height="30" Margin="32,0,0,0" Style="{StaticResource BadgeChromeDanger}">
<Button Content="{x:Static langs:Lang.Reply}"/>
</controls:Badge>
</StackPanel>