控件功能
根据自定义行和列,快速进行排列,能够进行自定义控件间距离,减少元素进行定义间距,同时能更好的维护界面排序。
代码部分
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
namespace WPFApp
{
public class AutoGrid : Grid
{
/// <summary>
/// 列定义 例如: "100,*,100" "100 * 100"
/// </summary>
[Category("Layout")]
public string Columns
{
get {
return (string)GetValue(ColumnsProperty); }
set {
SetValue(ColumnsProperty, value); }
}
public static readonly DependencyProperty ColumnsProperty =
DependencyProperty.Register(nameof(Columns), typeof(string), typeof(AutoGrid), new PropertyMetadata("", ColumnsChanged));
/// <summary>
/// 行定义 例如: "100,*,100" "100 * 100"
/// </summary>
[Category("Layout")]
public string Rows
{
get {
return (string)GetValue(RowsProperty); }
set {
SetValue(RowsProperty, value); }
}
public static readonly DependencyProperty RowsProperty =
DependencyProperty.Register(nameof(Rows), typeof(string), typeof(AutoGrid), new PropertyMetadata("", RowsChange));
/// <summary>
/// 排列方式
/// </summary>
[Category("Layout")]
public Orientation Orientation
{
get {
return (Orientation)GetValue(OrientationProperty); }
set {
SetValue(OrientationProperty, value); }
}
public static readonly DependencyProperty OrientationProperty =
DependencyProperty.Register(nameof(Orientation), typeof(Orientation),