Skip to content

Commit 3a0f501

Browse files
Split out properties into a separate file for ConstrainedBox
1 parent 0fd2a37 commit 3a0f501

File tree

2 files changed

+85
-63
lines changed

2 files changed

+85
-63
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using Windows.Foundation;
11+
using Windows.UI.Xaml;
12+
using Windows.UI.Xaml.Controls;
13+
14+
namespace Microsoft.Toolkit.Uwp.UI.Controls
15+
{
16+
/// <summary>
17+
/// The <see cref="ConstrainedBox"/> is a <see cref="FrameworkElement"/> control akin to <see cref="Viewbox"/>
18+
/// which can modify the behavior of it's child element's layout. <see cref="ConstrainedBox"/> restricts the
19+
/// available size for its content based on a scale factor and/or a specific <see cref="AspectRatio"/>.
20+
/// This is performed as a layout calculation modification.
21+
/// </summary>
22+
/// <remarks>
23+
/// Note that this class being implemented as a <see cref="ContentPresenter"/> is an implementation detail, and
24+
/// is not meant to be used as one with a template. It is recommended to avoid styling the frame of the control
25+
/// with borders and not using <see cref="ContentPresenter.ContentTemplate"/> for future compatibility of your
26+
/// code if moving to WinUI 3 in the future.
27+
/// </remarks>
28+
public partial class ConstrainedBox
29+
{
30+
/// <summary>
31+
/// Gets or sets aspect Ratio to use for the contents of the Panel (after scaling).
32+
/// </summary>
33+
public AspectRatio AspectRatio
34+
{
35+
get { return (AspectRatio)GetValue(AspectRatioProperty); }
36+
set { SetValue(AspectRatioProperty, value); }
37+
}
38+
39+
/// <summary>
40+
/// Identifies the <see cref="AspectRatio"/> property.
41+
/// </summary>
42+
public static readonly DependencyProperty AspectRatioProperty =
43+
DependencyProperty.Register(nameof(AspectRatio), typeof(AspectRatio), typeof(ConstrainedBox), new PropertyMetadata(null, ConstraintPropertyChanged));
44+
45+
/// <summary>
46+
/// Gets or sets the scale for the width of the panel. Should be a value between 0-1.0. Default is 1.0.
47+
/// </summary>
48+
public double ScaleX
49+
{
50+
get { return (double)GetValue(ScaleXProperty); }
51+
set { SetValue(ScaleXProperty, value); }
52+
}
53+
54+
/// <summary>
55+
/// Identifies the <see cref="ScaleX"/> property.
56+
/// </summary>
57+
public static readonly DependencyProperty ScaleXProperty =
58+
DependencyProperty.Register(nameof(ScaleX), typeof(double), typeof(ConstrainedBox), new PropertyMetadata(1.0, ConstraintPropertyChanged));
59+
60+
/// <summary>
61+
/// Gets or sets the scale for the height of the panel. Should be a value between 0-1.0. Default is 1.0.
62+
/// </summary>
63+
public double ScaleY
64+
{
65+
get { return (double)GetValue(ScaleYProperty); }
66+
set { SetValue(ScaleYProperty, value); }
67+
}
68+
69+
/// <summary>
70+
/// Identifies the <see cref="ScaleY"/> property.
71+
/// </summary>
72+
public static readonly DependencyProperty ScaleYProperty =
73+
DependencyProperty.Register(nameof(ScaleY), typeof(double), typeof(ConstrainedBox), new PropertyMetadata(1.0, ConstraintPropertyChanged));
74+
75+
private static void ConstraintPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
76+
{
77+
if (d is ConstrainedBox panel)
78+
{
79+
panel.InvalidateMeasure();
80+
}
81+
}
82+
}
83+
}

Microsoft.Toolkit.Uwp.UI.Controls.Primitives/ConstrainedBox/ConstrainedBox.cs

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
1616
/// <summary>
1717
/// The <see cref="ConstrainedBox"/> is a <see cref="FrameworkElement"/> control akin to <see cref="Viewbox"/>
1818
/// which can modify the behavior of it's child element's layout. <see cref="ConstrainedBox"/> restricts the
19-
/// available size for its content based on a scale factor and/or a specific <see cref="AspectRatio"/>.
19+
/// available size for its content based on a scale factor, multiple factor, and/or a specific <see cref="AspectRatio"/>, in that order.
2020
/// This is performed as a layout calculation modification.
2121
/// </summary>
2222
/// <remarks>
@@ -25,69 +25,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
2525
/// with borders and not using <see cref="ContentPresenter.ContentTemplate"/> for future compatibility of your
2626
/// code if moving to WinUI 3 in the future.
2727
/// </remarks>
28-
public class ConstrainedBox : ContentPresenter // TODO: Should be FrameworkElement directly, see https://github.com/microsoft/microsoft-ui-xaml/issues/5530
28+
public partial class ConstrainedBox : ContentPresenter // TODO: Should be FrameworkElement directly, see https://github.com/microsoft/microsoft-ui-xaml/issues/5530
2929
{
30-
/// <summary>
31-
/// Gets or sets aspect Ratio to use for the contents of the Panel (after scaling).
32-
/// </summary>
33-
public AspectRatio AspectRatio
34-
{
35-
get { return (AspectRatio)GetValue(AspectRatioProperty); }
36-
set { SetValue(AspectRatioProperty, value); }
37-
}
38-
39-
/// <summary>
40-
/// Identifies the <see cref="AspectRatio"/> property.
41-
/// </summary>
42-
public static readonly DependencyProperty AspectRatioProperty =
43-
DependencyProperty.Register(nameof(AspectRatio), typeof(AspectRatio), typeof(ConstrainedBox), new PropertyMetadata(null, AspectRatioPropertyChanged));
44-
45-
private static void AspectRatioPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
46-
{
47-
if (d is ConstrainedBox panel)
48-
{
49-
panel.InvalidateMeasure();
50-
}
51-
}
52-
53-
/// <summary>
54-
/// Gets or sets the scale for the width of the panel. Should be a value between 0-1.0. Default is 1.0.
55-
/// </summary>
56-
public double ScaleX
57-
{
58-
get { return (double)GetValue(ScaleXProperty); }
59-
set { SetValue(ScaleXProperty, value); }
60-
}
61-
62-
/// <summary>
63-
/// Identifies the <see cref="ScaleX"/> property.
64-
/// </summary>
65-
public static readonly DependencyProperty ScaleXProperty =
66-
DependencyProperty.Register(nameof(ScaleX), typeof(double), typeof(ConstrainedBox), new PropertyMetadata(1.0, ScalePropertyChanged));
67-
68-
/// <summary>
69-
/// Gets or sets the scale for the height of the panel. Should be a value between 0-1.0. Default is 1.0.
70-
/// </summary>
71-
public double ScaleY
72-
{
73-
get { return (double)GetValue(ScaleYProperty); }
74-
set { SetValue(ScaleYProperty, value); }
75-
}
76-
77-
/// <summary>
78-
/// Identifies the <see cref="ScaleY"/> property.
79-
/// </summary>
80-
public static readonly DependencyProperty ScaleYProperty =
81-
DependencyProperty.Register(nameof(ScaleY), typeof(double), typeof(ConstrainedBox), new PropertyMetadata(1.0, ScalePropertyChanged));
82-
83-
private static void ScalePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
84-
{
85-
if (d is ConstrainedBox panel)
86-
{
87-
panel.InvalidateMeasure();
88-
}
89-
}
90-
9130
private bool IsPositiveRealNumber(double value) => !double.IsNaN(value) && !double.IsInfinity(value) && value > 0;
9231

9332
private Size _lastMeasuredSize;

0 commit comments

Comments
 (0)