4 using System.Windows.Documents;
5 using System.Windows.Media;
7 namespace SiliconStudio.Presentation.Adorners
14 private Brush renderBrush;
15 private Pen renderPen;
20 public static readonly DependencyProperty AcceptBorderBrushProperty = DependencyProperty.Register(
"AcceptBorderBrush", typeof(Brush), typeof(
HighlightBorderAdorner),
new PropertyMetadata(Brushes.PaleGreen, PropertyChanged));
25 public static readonly DependencyProperty AcceptBorderThicknessProperty = DependencyProperty.Register(
"AcceptBorderThickness", typeof(
double), typeof(
HighlightBorderAdorner),
new PropertyMetadata(2.0, PropertyChanged));
30 public static readonly DependencyProperty AcceptBorderCornerRadiusProperty = DependencyProperty.Register(
"AcceptBorderCornerRadius", typeof(
double), typeof(
HighlightBorderAdorner),
new PropertyMetadata(3.0, PropertyChanged));
35 public static readonly DependencyProperty AcceptBackgroundBrushProperty = DependencyProperty.Register(
"AcceptBackgroundBrush", typeof(Brush), typeof(
HighlightBorderAdorner),
new PropertyMetadata(Brushes.MediumSeaGreen, PropertyChanged));
40 public static readonly DependencyProperty AcceptBackgroundOpacityProperty = DependencyProperty.Register(
"AcceptBackgroundOpacity", typeof(
double), typeof(
HighlightBorderAdorner),
new PropertyMetadata(0.3, PropertyChanged));
45 public static readonly DependencyProperty RefuseBorderBrushProperty = DependencyProperty.Register(
"RefuseBorderBrush", typeof(Brush), typeof(
HighlightBorderAdorner),
new PropertyMetadata(Brushes.Red, PropertyChanged));
50 public static readonly DependencyProperty RefuseBorderThicknessProperty = DependencyProperty.Register(
"RefuseBorderThickness", typeof(
double), typeof(
HighlightBorderAdorner),
new PropertyMetadata(2.0, PropertyChanged));
55 public static readonly DependencyProperty RefuseBorderCornerRadiusProperty = DependencyProperty.Register(
"RefuseBorderCornerRadius", typeof(
double), typeof(
HighlightBorderAdorner),
new PropertyMetadata(3.0, PropertyChanged));
60 public static readonly DependencyProperty RefuseBackgroundBrushProperty = DependencyProperty.Register(
"RefuseBackgroundBrush", typeof(Brush), typeof(
HighlightBorderAdorner),
new PropertyMetadata(Brushes.IndianRed, PropertyChanged));
65 public static readonly DependencyProperty RefuseBackgroundOpacityProperty = DependencyProperty.Register(
"RefuseBackgroundOpacity", typeof(
double), typeof(
HighlightBorderAdorner),
new PropertyMetadata(0.3, PropertyChanged));
70 public static readonly DependencyProperty BorderBrushProperty = DependencyProperty.Register(
"BorderBrush", typeof(Brush), typeof(
HighlightBorderAdorner),
new PropertyMetadata(Brushes.SteelBlue, PropertyChanged));
75 public static readonly DependencyProperty BorderThicknessProperty = DependencyProperty.Register(
"BorderThickness", typeof(
double), typeof(
HighlightBorderAdorner),
new PropertyMetadata(2.0, PropertyChanged));
80 public static readonly DependencyProperty BorderCornerRadiusProperty = DependencyProperty.Register(
"BorderCornerRadius", typeof(
double), typeof(
HighlightBorderAdorner),
new PropertyMetadata(3.0, PropertyChanged));
85 public static readonly DependencyProperty BackgroundBrushProperty = DependencyProperty.Register(
"BackgroundBrush", typeof(Brush), typeof(
HighlightBorderAdorner),
new PropertyMetadata(Brushes.LightSteelBlue, PropertyChanged));
90 public static readonly DependencyProperty BackgroundOpacityProperty = DependencyProperty.Register(
"BackgroundOpacity", typeof(
double), typeof(
HighlightBorderAdorner),
new PropertyMetadata(0.3, PropertyChanged));
102 : base(adornedElement)
109 public Brush AcceptBorderBrush {
get {
return (Brush)GetValue(AcceptBorderBrushProperty); } set { SetValue(AcceptBorderBrushProperty, value); } }
114 public double AcceptBorderThickness {
get {
return (
double)GetValue(AcceptBorderThicknessProperty); } set { SetValue(AcceptBorderThicknessProperty, value); } }
119 public double AcceptBorderCornerRadius {
get {
return (
double)GetValue(AcceptBorderCornerRadiusProperty); } set { SetValue(AcceptBorderCornerRadiusProperty, value); } }
124 public Brush AcceptBackgroundBrush {
get {
return (Brush)GetValue(AcceptBackgroundBrushProperty); } set { SetValue(AcceptBackgroundBrushProperty, value); } }
129 public double AcceptBackgroundOpacity {
get {
return (
double)GetValue(AcceptBackgroundOpacityProperty); } set { SetValue(AcceptBackgroundOpacityProperty, value); } }
134 public Brush RefuseBorderBrush {
get {
return (Brush)GetValue(RefuseBorderBrushProperty); } set { SetValue(RefuseBorderBrushProperty, value); } }
139 public double RefuseBorderThickness {
get {
return (
double)GetValue(RefuseBorderThicknessProperty); } set { SetValue(RefuseBorderThicknessProperty, value); } }
144 public double RefuseBorderCornerRadius {
get {
return (
double)GetValue(RefuseBorderCornerRadiusProperty); } set { SetValue(RefuseBorderCornerRadiusProperty, value); } }
149 public Brush RefuseBackgroundBrush {
get {
return (Brush)GetValue(RefuseBackgroundBrushProperty); } set { SetValue(RefuseBackgroundBrushProperty, value); } }
154 public double RefuseBackgroundOpacity {
get {
return (
double)GetValue(RefuseBackgroundOpacityProperty); } set { SetValue(RefuseBackgroundOpacityProperty, value); } }
159 public Brush BorderBrush {
get {
return (Brush)GetValue(BorderBrushProperty); } set { SetValue(BorderBrushProperty, value); } }
164 public double BorderThickness {
get {
return (
double)GetValue(BorderThicknessProperty); } set { SetValue(BorderThicknessProperty, value); } }
169 public double BorderCornerRadius {
get {
return (
double)GetValue(BorderCornerRadiusProperty); } set { SetValue(BorderCornerRadiusProperty, value); } }
174 public Brush BackgroundBrush {
get {
return (Brush)GetValue(BackgroundBrushProperty); } set { SetValue(BackgroundBrushProperty, value); } }
179 public double BackgroundOpacity {
get {
return (
double)GetValue(BackgroundOpacityProperty); } set { SetValue(BackgroundOpacityProperty, value); } }
187 protected override void OnRender(DrawingContext drawingContext)
189 var adornedElementRect =
new Rect(AdornedElement.RenderSize);
193 case HighlightAdornerState.HighlightAccept:
194 renderBrush = AcceptBackgroundBrush.Clone();
195 renderBrush.Opacity = AcceptBackgroundOpacity;
196 renderPen =
new Pen(AcceptBorderBrush, AcceptBorderThickness);
197 drawingContext.DrawRoundedRectangle(renderBrush, renderPen, adornedElementRect, AcceptBorderCornerRadius, AcceptBorderCornerRadius);
199 case HighlightAdornerState.HighlightRefuse:
200 renderBrush = RefuseBackgroundBrush.Clone();
201 renderBrush.Opacity = RefuseBackgroundOpacity;
202 renderPen =
new Pen(RefuseBorderBrush, RefuseBorderThickness);
203 drawingContext.DrawRoundedRectangle(renderBrush, renderPen, adornedElementRect, RefuseBorderCornerRadius, RefuseBorderCornerRadius);
205 case HighlightAdornerState.Visible:
206 renderBrush = BackgroundBrush.Clone();
207 renderBrush.Opacity = BackgroundOpacity;
208 renderPen =
new Pen(BorderBrush, BorderThickness);
209 drawingContext.DrawRoundedRectangle(renderBrush, renderPen, adornedElementRect, BorderCornerRadius, BorderCornerRadius);
214 private static void PropertyChanged(
DependencyObject d, DependencyPropertyChangedEventArgs e)
217 adorner.InvalidateVisual();
override void OnRender(DrawingContext drawingContext)
An adorner that draw a rectangle with borders over the adorned element. It can multiple possible stat...
HighlightBorderAdorner(UIElement adornedElement)
Initializes a new instance of the HighlightBorderAdorner class.