add WaterfallPanel

This commit is contained in:
NaBian committed 2018-12-28 00:14:09 +08:00
1 parent c2f26ae942
commit 3857ac2d53
15 files changed
+227 -2

No files matched your search

@@ -0,0 +1,85 @@
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using HandyControl.Data;
namespace HandyControl.Controls
{
public class WaterfallPanel : Panel
{
public static readonly DependencyProperty GroupsProperty = DependencyProperty.Register(
"Groups", typeof(int), typeof(WaterfallPanel), new FrameworkPropertyMetadata(ValueBoxes.Int2Box, FrameworkPropertyMetadataOptions.AffectsMeasure), IsGroupsValid);
public int Groups
{
get => (int) GetValue(GroupsProperty);
set => SetValue(GroupsProperty, value);
}
private static bool IsGroupsValid(object value)
{
var v = (int)value;
return v >= 1;
}
public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register(
"Orientation", typeof(Orientation), typeof(WaterfallPanel), new FrameworkPropertyMetadata(
Orientation.Horizontal, FrameworkPropertyMetadataOptions.AffectsMeasure));
public Orientation Orientation
{
get => (Orientation) GetValue(OrientationProperty);
set => SetValue(OrientationProperty, value);
}
protected override Size MeasureOverride(Size constraint)
{
if (Groups < 1) return constraint;
var children = InternalChildren;
Size panelSize;
if (Orientation == Orientation.Horizontal)
{
var heightArr = new double[Groups].ToList();
var itemWidth = constraint.Width / Groups;
if (double.IsNaN(itemWidth) || double.IsInfinity(itemWidth)) return constraint;
for (int i = 0, count = children.Count; i < count; i++)
{
var child = children[i];
if (child == null) continue;
child.Measure(constraint);
var minIndex = heightArr.IndexOf(heightArr.Min());
var minY = heightArr[minIndex];
child.Arrange(new Rect(new Point(minIndex * itemWidth, minY), new Size(itemWidth, child.DesiredSize.Height)));
heightArr[minIndex] = minY + child.DesiredSize.Height;
}
panelSize = new Size(constraint.Width, heightArr.Max());
}
else
{
var widthArr = new double[Groups].ToList();
var itemHeight = constraint.Height / Groups;
if (double.IsNaN(itemHeight) || double.IsInfinity(itemHeight)) return constraint;
for (int i = 0, count = children.Count; i < count; i++)
{
var child = children[i];
if (child == null) continue;
child.Measure(constraint);
var minIndex = widthArr.IndexOf(widthArr.Min());
var minX = widthArr[minIndex];
child.Arrange(new Rect(new Point(minX, minIndex * itemHeight), new Size(child.DesiredSize.Width, itemHeight)));
widthArr[minIndex] = minX + child.DesiredSize.Width;
}
panelSize = new Size(widthArr.Max(), constraint.Height);
}
return panelSize;
}
}
}
+2
View File
@@ -23,6 +23,8 @@
internal static object Int1Box = 1;
internal static object Int2Box = 2;
internal static object Int5Box = 5;
internal static object BooleanBox(bool value) => value ? TrueBox : FalseBox;
+1
View File
@@ -134,6 +134,7 @@
<Compile Include="Controls\Other\CircleProgressBar.cs" />
<Compile Include="Controls\Other\RadioGroup.cs" />
<Compile Include="Controls\Other\Shield.cs" />
<Compile Include="Controls\Panel\WaterfallPanel.cs" />
<Compile Include="Controls\Rate\Rate.cs" />
<Compile Include="Controls\Rate\RateItem.cs" />
<Compile Include="Controls\Text\OutlineText.cs" />
+2
View File
@@ -68,6 +68,8 @@
public static readonly string ShieldDemoCtl = nameof(ShieldDemoCtl);
public static readonly string WaterfallPanelDemoCtl = nameof(WaterfallPanelDemoCtl);
public static readonly string ButtonDemoCtl = nameof(ButtonDemoCtl);
public static readonly string ToggleButtonDemoCtl = nameof(ToggleButtonDemoCtl);
+2 -1
View File
@@ -36,7 +36,8 @@ var controlList = new List<string>
"QQGroupView",
"BlurWindow",
"RateDemoCtl",
"ShieldDemoCtl"
"ShieldDemoCtl",
"WaterfallPanelDemoCtl"
};
var styleList = new List<string>
{
+8
View File
@@ -196,6 +196,9 @@
<Compile Include="UserControl\Controls\TimePickerDemoCtl.xaml.cs">
<DependentUpon>TimePickerDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="UserControl\Controls\WaterfallPanelDemoCtl.xaml.cs">
<DependentUpon>WaterfallPanelDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="UserControl\Controls\WindowDemoCtl.xaml.cs">
<DependentUpon>WindowDemoCtl.xaml</DependentUpon>
</Compile>
@@ -491,6 +494,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControl\Controls\WaterfallPanelDemoCtl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControl\Controls\WindowDemoCtl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -671,6 +678,7 @@
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>MessageToken.cs</LastGenOutput>
</Content>
<Resource Include="Resources\Img\LeftMainContent\Panel_16x.png" />
<Resource Include="Resources\Img\LeftMainContent\Shield_16x.png" />
<Resource Include="Resources\Img\LeftMainContent\Star.png" />
<Resource Include="Resources\Img\qq-group.jpg" />
+19 -1
View File
@@ -47,7 +47,7 @@ namespace HandyControlDemo.Properties.Langs {
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性
/// 使用此强类型资源类,为所有资源查找
/// 重写当前线程的 CurrentUICulture 属性。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
@@ -411,6 +411,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
/// <summary>
/// 查找类似 组数 的本地化字符串。
/// </summary>
public static string Groups {
get {
return ResourceManager.GetString("Groups", resourceCulture);
}
}
/// <summary>
/// 查找类似 信息通知 的本地化字符串。
/// </summary>
@@ -1050,6 +1059,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
/// <summary>
/// 查找类似 瀑布流 的本地化字符串。
/// </summary>
public static string WaterfallPanel {
get {
return ResourceManager.GetString("WaterfallPanel", resourceCulture);
}
}
/// <summary>
/// 查找类似 窗口 的本地化字符串。
/// </summary>
@@ -450,4 +450,10 @@
<data name="Shield" xml:space="preserve">
<value>Shield</value>
</data>
<data name="WaterfallPanel" xml:space="preserve">
<value>WaterfallPanel</value>
</data>
<data name="Groups" xml:space="preserve">
<value>Groups</value>
</data>
</root>
@@ -430,4 +430,10 @@
<data name="Shield" xml:space="preserve">
<value>徽章</value>
</data>
<data name="WaterfallPanel" xml:space="preserve">
<value>瀑布流</value>
</data>
<data name="Groups" xml:space="preserve">
<value>组数</value>
</data>
</root>
Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

@@ -0,0 +1,77 @@
<UserControl x:Class="HandyControlDemo.UserControl.WaterfallPanelDemoCtl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl"
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
xmlns:interactivity="clr-namespace:HandyControl.Interactivity;assembly=HandyControl"
Background="{DynamicResource RegionBrush}">
<ContentControl>
<Grid Margin="32">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<controls:NumericUpDown x:Name="UpDownGroups" HorizontalAlignment="Center" Value="2" Minimum="1" Maximum="3" Width="200" Style="{StaticResource NumericUpDownExtend}" controls:TitleElement.Title="{x:Static langs:Lang.Groups}" controls:TitleElement.TitleWidth="50" controls:TitleElement.TitleAlignment="Left"/>
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,16,0,0">
<controls:ScrollViewer MaxHeight="300" IsEnableInertia="True">
<controls:WaterfallPanel VerticalAlignment="Center" Width="300" Groups="{Binding Value,ElementName=UpDownGroups}">
<interactivity:Interaction.Behaviors>
<interactivity:FluidMoveBehavior AppliesTo="Children" Duration="0:0:.2">
<interactivity:FluidMoveBehavior.EaseX>
<PowerEase/>
</interactivity:FluidMoveBehavior.EaseX>
<interactivity:FluidMoveBehavior.EaseY>
<PowerEase/>
</interactivity:FluidMoveBehavior.EaseY>
</interactivity:FluidMoveBehavior>
</interactivity:Interaction.Behaviors>
<Border Height="100" Background="{DynamicResource PrimaryBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
<TextBlock Text="{x:Static langs:Lang.ContentDemoStr}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
</Border>
<Border Height="140" Background="{DynamicResource DangerBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
<TextBlock Text="{x:Static langs:Lang.ContentDemoStr}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
</Border>
<Border Height="100" Background="{DynamicResource SuccessBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
<TextBlock Text="{x:Static langs:Lang.ContentDemoStr}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
</Border>
<Border Height="170" Background="{DynamicResource InfoBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
<TextBlock Text="{x:Static langs:Lang.ContentDemoStr}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
</Border>
<Border Height="100" Background="{DynamicResource WarningBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
<TextBlock Text="{x:Static langs:Lang.ContentDemoStr}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
</Border>
</controls:WaterfallPanel>
</controls:ScrollViewer>
<controls:ScrollViewer Margin="32,0,0,0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden" Orientation="Horizontal" IsEnableInertia="True" MaxWidth="300">
<controls:WaterfallPanel VerticalAlignment="Center" Height="300" Orientation="Vertical" Groups="{Binding Value,ElementName=UpDownGroups}">
<interactivity:Interaction.Behaviors>
<interactivity:FluidMoveBehavior AppliesTo="Children" Duration="0:0:.2">
<interactivity:FluidMoveBehavior.EaseX>
<PowerEase/>
</interactivity:FluidMoveBehavior.EaseX>
<interactivity:FluidMoveBehavior.EaseY>
<PowerEase/>
</interactivity:FluidMoveBehavior.EaseY>
</interactivity:FluidMoveBehavior>
</interactivity:Interaction.Behaviors>
<Border Width="100" Background="{DynamicResource PrimaryBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
<TextBlock Text="{x:Static langs:Lang.ContentDemoStr}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
</Border>
<Border Width="140" Background="{DynamicResource DangerBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
<TextBlock Text="{x:Static langs:Lang.ContentDemoStr}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
</Border>
<Border Width="100" Background="{DynamicResource SuccessBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
<TextBlock Text="{x:Static langs:Lang.ContentDemoStr}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
</Border>
<Border Width="170" Background="{DynamicResource InfoBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
<TextBlock Text="{x:Static langs:Lang.ContentDemoStr}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
</Border>
<Border Width="100" Background="{DynamicResource WarningBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
<TextBlock Text="{x:Static langs:Lang.ContentDemoStr}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
</Border>
</controls:WaterfallPanel>
</controls:ScrollViewer>
</StackPanel>
</Grid>
</ContentControl>
</UserControl>
@@ -0,0 +1,10 @@
namespace HandyControlDemo.UserControl
{
public partial class WaterfallPanelDemoCtl
{
public WaterfallPanelDemoCtl()
{
InitializeComponent();
}
}
}
@@ -230,6 +230,11 @@
<Image Source="../../Resources/Img/LeftMainContent/ColorWheel_16x.png"/>
</controls:EdgeElement.LeftContent>
</ListBoxItem>
<ListBoxItem Style="{StaticResource ListBoxItemNew}" Tag="{x:Static data:MessageToken.WaterfallPanelDemoCtl}" Content="{x:Static langs:Lang.WaterfallPanel}">
<controls:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/Panel_16x.png"/>
</controls:EdgeElement.LeftContent>
</ListBoxItem>
<ListBoxItem Tag="{x:Static data:MessageToken.CircleProgressBarDemoCtl}" Content="{x:Static langs:Lang.CircleProgressBar}">
<controls:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/ShapeArcRing_16x.png"/>
+4
View File
@@ -6,6 +6,10 @@
## Latest examples
### WaterfallPanel
![WaterfallPanel](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/WaterfallPanel.png)
### Rate
![Rate](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/Rate.png)
Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB