2023-08-11 16:44:28 +00:00
|
|
|
|
using Panuon.WPF.UI;
|
|
|
|
|
using System;
|
2023-06-05 08:42:20 +00:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls.Primitives;
|
|
|
|
|
|
|
|
|
|
namespace VPet_Simulator.Windows
|
|
|
|
|
{
|
|
|
|
|
public class AutoUniformGrid
|
|
|
|
|
: UniformGrid
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#region ItemsMinWidth
|
|
|
|
|
public double ItemsMinWidth
|
|
|
|
|
{
|
|
|
|
|
get { return (double)GetValue(ItemsMinWidthProperty); }
|
|
|
|
|
set { SetValue(ItemsMinWidthProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty ItemsMinWidthProperty =
|
|
|
|
|
DependencyProperty.Register("ItemsMinWidth", typeof(double), typeof(AutoUniformGrid), new PropertyMetadata(double.NaN));
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ItemsMinHeight
|
|
|
|
|
public double ItemsMinHeight
|
|
|
|
|
{
|
|
|
|
|
get { return (double)GetValue(ItemsMinHeightProperty); }
|
|
|
|
|
set { SetValue(ItemsMinHeightProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty ItemsMinHeightProperty =
|
|
|
|
|
DependencyProperty.Register("ItemsMinHeight", typeof(double), typeof(AutoUniformGrid), new PropertyMetadata(double.NaN));
|
|
|
|
|
#endregion
|
|
|
|
|
|
2023-08-11 16:44:28 +00:00
|
|
|
|
public event RoutedEventHandler Changed
|
|
|
|
|
{
|
|
|
|
|
add { AddHandler(ChangedEvent, value); }
|
|
|
|
|
remove { RemoveHandler(ChangedEvent, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static readonly RoutedEvent ChangedEvent =
|
|
|
|
|
EventManager.RegisterRoutedEvent("Changed", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AutoUniformGrid));
|
|
|
|
|
|
2023-06-05 08:42:20 +00:00
|
|
|
|
|
|
|
|
|
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
|
|
|
|
|
{
|
|
|
|
|
base.OnRenderSizeChanged(sizeInfo);
|
|
|
|
|
|
2023-08-11 16:44:28 +00:00
|
|
|
|
var isChanged = false;
|
2023-06-05 08:42:20 +00:00
|
|
|
|
if (!double.IsNaN(ItemsMinWidth))
|
|
|
|
|
{
|
|
|
|
|
var columns = (int)Math.Floor(sizeInfo.NewSize.Width / ItemsMinWidth);
|
2023-08-11 16:44:28 +00:00
|
|
|
|
if(Columns != columns)
|
|
|
|
|
{
|
|
|
|
|
isChanged = true;
|
|
|
|
|
}
|
2023-06-05 08:42:20 +00:00
|
|
|
|
SetCurrentValue(ColumnsProperty, columns);
|
|
|
|
|
}
|
|
|
|
|
if (!double.IsNaN(ItemsMinHeight))
|
|
|
|
|
{
|
|
|
|
|
var rows = (int)Math.Floor(sizeInfo.NewSize.Height / ItemsMinHeight);
|
2023-08-11 16:44:28 +00:00
|
|
|
|
if(Rows != rows)
|
|
|
|
|
{
|
|
|
|
|
isChanged = true;
|
|
|
|
|
}
|
2023-06-05 08:42:20 +00:00
|
|
|
|
SetCurrentValue(RowsProperty, rows);
|
|
|
|
|
}
|
2023-08-11 16:44:28 +00:00
|
|
|
|
if(isChanged)
|
|
|
|
|
{
|
|
|
|
|
RaiseEvent(new RoutedEventArgs(ChangedEvent));
|
|
|
|
|
}
|
2023-06-05 08:42:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|