Skip to content

Instantly share code, notes, and snippets.

@kusa-mochi
Created August 3, 2018 15:12
Show Gist options
  • Save kusa-mochi/4913e8dd142c6897c8434c4a9d3b5ffa to your computer and use it in GitHub Desktop.
Save kusa-mochi/4913e8dd142c6897c8434c4a9d3b5ffa to your computer and use it in GitHub Desktop.
using System.Windows;
using System.Windows.Controls;
namespace CommonControlParts
{
/// <summary>
/// 4つの角のCornerRadiusをXAMLから個別に指定できるようにしたBorder
/// </summary>
public class PartialCornerBorder : Border
{
#region 依存関係プロパティ TopLeftCornerRadius
public double TopLeftCornerRadius
{
get { return (double)this.GetValue(TopLeftCornerRadiusProperty); }
set { this.SetValue(TopLeftCornerRadiusProperty, value); }
}
public static readonly DependencyProperty TopLeftCornerRadiusProperty = DependencyProperty.Register(
"TopLeftCornerRadius", typeof(double), typeof(PartialCornerBorder), new PropertyMetadata(0.0,
(d, e) =>
{
PartialCornerBorder b = d as PartialCornerBorder;
if (b != null)
{
b.CornerRadius = new CornerRadius(
(double)e.NewValue,
b.CornerRadius.TopRight,
b.CornerRadius.BottomRight,
b.CornerRadius.BottomLeft
);
}
}
));
#endregion
#region 依存関係プロパティ TopRightCornerRadius
public double TopRightCornerRadius
{
get { return (double)this.GetValue(TopRightCornerRadiusProperty); }
set { this.SetValue(TopRightCornerRadiusProperty, value); }
}
public static readonly DependencyProperty TopRightCornerRadiusProperty = DependencyProperty.Register(
"TopRightCornerRadius", typeof(double), typeof(PartialCornerBorder), new PropertyMetadata(0.0,
(d, e) =>
{
PartialCornerBorder b = d as PartialCornerBorder;
if (b != null)
{
b.CornerRadius = new CornerRadius(
b.CornerRadius.TopLeft,
(double)e.NewValue,
b.CornerRadius.BottomRight,
b.CornerRadius.BottomLeft
);
}
}
));
#endregion
#region 依存関係プロパティ BottomRightCornerRadius
public double BottomRightCornerRadius
{
get { return (double)this.GetValue(BottomRightCornerRadiusProperty); }
set { this.SetValue(BottomRightCornerRadiusProperty, value); }
}
public static readonly DependencyProperty BottomRightCornerRadiusProperty = DependencyProperty.Register(
"BottomRightCornerRadius", typeof(double), typeof(PartialCornerBorder), new PropertyMetadata(0.0,
(d, e) =>
{
PartialCornerBorder b = d as PartialCornerBorder;
if (b != null)
{
b.CornerRadius = new CornerRadius(
b.CornerRadius.TopLeft,
b.CornerRadius.TopRight,
(double)e.NewValue,
b.CornerRadius.BottomLeft
);
}
}
));
#endregion
#region 依存関係プロパティ BottomLeftCornerRadius
public double BottomLeftCornerRadius
{
get { return (double)this.GetValue(BottomLeftCornerRadiusProperty); }
set { this.SetValue(BottomLeftCornerRadiusProperty, value); }
}
public static readonly DependencyProperty BottomLeftCornerRadiusProperty = DependencyProperty.Register(
"BottomLeftCornerRadius", typeof(double), typeof(PartialCornerBorder), new PropertyMetadata(0.0,
(d, e) =>
{
PartialCornerBorder b = d as PartialCornerBorder;
if (b != null)
{
b.CornerRadius = new CornerRadius(
b.CornerRadius.TopLeft,
b.CornerRadius.TopRight,
b.CornerRadius.BottomRight,
(double)e.NewValue
);
}
}
));
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment