Skip to content

Commit d38f8a9

Browse files
authored
Merge branch 'main' into dwm
2 parents 8e6918a + 4da8129 commit d38f8a9

23 files changed

Lines changed: 177 additions & 86 deletions

ReadMe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Please read the [Getting Started with the Windows Community Toolkit](https://doc
2121
> [!NOTE]
2222
> If you're updating from a pre-8.x version of the Windows Community Toolkit, see [our migration notes here](https://aka.ms/toolkit/windows/migration).
2323
24-
## Windows Community Toolkit Gallery app
24+
## <sub><img src="icon.png" width="24" height="24" hspace="4"></sub> Windows Community Toolkit Gallery app
2525

2626
Want to see the Toolkit in action before jumping into the code? Download and play with the [Windows Community Toolkit Gallery](https://aka.ms/windowstoolkitapp) from the Microsoft Store.
2727

components/Behaviors/src/Animations/StartAnimationAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public UIElement TargetObject
4545
public static readonly DependencyProperty TargetObjectProperty = DependencyProperty.Register(
4646
nameof(TargetObject),
4747
typeof(UIElement),
48-
typeof(StartAnimationActivity),
48+
typeof(StartAnimationAction),
4949
new PropertyMetadata(null));
5050

5151
/// <inheritdoc/>

components/Extensions/samples/Dispatcher/KeyboardDebounceSample.xaml renamed to components/Extensions/samples/DispatcherQueueTimerExtensions/KeyboardDebounceSample.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Page x:Class="ExtensionsExperiment.Samples.DispatcherQueueExtensions.KeyboardDebounceSample"
1+
<Page x:Class="ExtensionsExperiment.Samples.DispatcherQueueTimerExtensions.KeyboardDebounceSample"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

components/Extensions/samples/Dispatcher/KeyboardDebounceSample.xaml.cs renamed to components/Extensions/samples/DispatcherQueueTimerExtensions/KeyboardDebounceSample.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
using DispatcherQueueTimer = Windows.System.DispatcherQueueTimer;
1212
#endif
1313

14-
namespace ExtensionsExperiment.Samples.DispatcherQueueExtensions;
14+
namespace ExtensionsExperiment.Samples.DispatcherQueueTimerExtensions;
1515

1616
[ToolkitSample(id: nameof(KeyboardDebounceSample), "DispatcherQueueTimer Debounce Keyboard", description: "A sample for showing how to use the DispatcherQueueTimer Debounce extension to smooth keyboard input.")]
1717
[ToolkitSampleNumericOption("Interval", 120, 60, 240)]

components/Extensions/samples/Dispatcher/MouseDebounceSample.xaml renamed to components/Extensions/samples/DispatcherQueueTimerExtensions/MouseDebounceSample.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Page x:Class="ExtensionsExperiment.Samples.DispatcherQueueExtensions.MouseDebounceSample"
1+
<Page x:Class="ExtensionsExperiment.Samples.DispatcherQueueTimerExtensions.MouseDebounceSample"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

components/Extensions/samples/Dispatcher/MouseDebounceSample.xaml.cs renamed to components/Extensions/samples/DispatcherQueueTimerExtensions/MouseDebounceSample.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
using DispatcherQueueTimer = Windows.System.DispatcherQueueTimer;
1212
#endif
1313

14-
namespace ExtensionsExperiment.Samples.DispatcherQueueExtensions;
14+
namespace ExtensionsExperiment.Samples.DispatcherQueueTimerExtensions;
1515

1616
[ToolkitSample(id: nameof(MouseDebounceSample), "DispatcherQueueTimer Debounce Mouse", description: "A sample for showing how to use the DispatcherQueueTimer Debounce extension to smooth mouse input.")]
1717
[ToolkitSampleNumericOption("Interval", 400, 300, 1000)]

components/LayoutTransformControl/src/LayoutTransformControl.Properties.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ private void UnsubscribeFromTransformPropertyChanges(Transform transform)
127127
foreach (var propertyChangeEventSource in propertyChangeEventSources)
128128
{
129129
propertyChangeEventSource.ValueChanged -= OnTransformPropertyChanged;
130+
propertyChangeEventSource.Unregister();
130131
}
131132

132133
_transformPropertyChangeEventSources.Remove(transform);
@@ -153,7 +154,7 @@ private void SubscribeToTransformPropertyChanges(Transform transform)
153154

154155
if (rotateTransform != null)
155156
{
156-
var anglePropertyChangeEventSource = new PropertyChangeEventSource<double>(rotateTransform, "Angle");
157+
var anglePropertyChangeEventSource = new PropertyChangeEventSource<double>(rotateTransform, RotateTransform.AngleProperty);
157158
anglePropertyChangeEventSource.ValueChanged += OnTransformPropertyChanged;
158159
propertyChangeEventSources.Add(anglePropertyChangeEventSource);
159160
return;
@@ -163,11 +164,11 @@ private void SubscribeToTransformPropertyChanges(Transform transform)
163164

164165
if (scaleTransform != null)
165166
{
166-
var scaleXPropertyChangeEventSource = new PropertyChangeEventSource<double>(scaleTransform, "ScaleX");
167+
var scaleXPropertyChangeEventSource = new PropertyChangeEventSource<double>(scaleTransform, ScaleTransform.ScaleXProperty);
167168
scaleXPropertyChangeEventSource.ValueChanged += OnTransformPropertyChanged;
168169
propertyChangeEventSources.Add(scaleXPropertyChangeEventSource);
169170

170-
var scaleYPropertyChangeEventSource = new PropertyChangeEventSource<double>(scaleTransform, "ScaleY");
171+
var scaleYPropertyChangeEventSource = new PropertyChangeEventSource<double>(scaleTransform, ScaleTransform.ScaleYProperty);
171172
scaleYPropertyChangeEventSource.ValueChanged += OnTransformPropertyChanged;
172173
propertyChangeEventSources.Add(scaleYPropertyChangeEventSource);
173174
return;
@@ -177,11 +178,11 @@ private void SubscribeToTransformPropertyChanges(Transform transform)
177178

178179
if (skewTransform != null)
179180
{
180-
var angleXPropertyChangeEventSource = new PropertyChangeEventSource<double>(skewTransform, "AngleX");
181+
var angleXPropertyChangeEventSource = new PropertyChangeEventSource<double>(skewTransform, SkewTransform.AngleXProperty);
181182
angleXPropertyChangeEventSource.ValueChanged += OnTransformPropertyChanged;
182183
propertyChangeEventSources.Add(angleXPropertyChangeEventSource);
183184

184-
var angleYPropertyChangeEventSource = new PropertyChangeEventSource<double>(skewTransform, "AngleY");
185+
var angleYPropertyChangeEventSource = new PropertyChangeEventSource<double>(skewTransform, SkewTransform.AngleYProperty);
185186
angleYPropertyChangeEventSource.ValueChanged += OnTransformPropertyChanged;
186187
propertyChangeEventSources.Add(angleYPropertyChangeEventSource);
187188
return;
@@ -194,7 +195,7 @@ private void SubscribeToTransformPropertyChanges(Transform transform)
194195
var matrixPropertyChangeEventSource =
195196
new PropertyChangeEventSource<double>(
196197
matrixTransform,
197-
"Matrix");
198+
MatrixTransform.MatrixProperty);
198199
matrixPropertyChangeEventSource.ValueChanged += OnTransformPropertyChanged;
199200
propertyChangeEventSources.Add(matrixPropertyChangeEventSource);
200201
}

components/LayoutTransformControl/src/LayoutTransformControl.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ namespace CommunityToolkit.WinUI.Controls;
99
/// Control that implements support for transformations as if applied by LayoutTransform.
1010
/// </summary>
1111
[ContentProperty(Name = "Child")]
12-
12+
[TemplatePart(Name = "LayoutRoot", Type = typeof(Panel))]
13+
[TemplatePart(Name = "MatrixTransform", Type = typeof(MatrixTransform))]
1314
public partial class LayoutTransformControl : Control
1415
{
16+
private static Size EmptySize => new Size();
17+
1518
/// <summary>
1619
/// Value used to work around double arithmetic rounding issues.
1720
/// </summary>
@@ -45,7 +48,7 @@ public partial class LayoutTransformControl : Control
4548
/// <summary>
4649
/// Actual DesiredSize of Child element.
4750
/// </summary>
48-
private Size _childActualSize = Size.Empty;
51+
private Size _childActualSize = EmptySize;
4952

5053
/// <summary>
5154
/// Initializes a new instance of the <see cref="LayoutTransformControl"/> class.
@@ -235,11 +238,11 @@ protected override Size MeasureOverride(Size availableSize)
235238
if (_layoutRoot == null || child == null)
236239
{
237240
// No content, no size
238-
return Size.Empty;
241+
return EmptySize;
239242
}
240243

241244
Size measureSize;
242-
if (_childActualSize == Size.Empty)
245+
if (_childActualSize == EmptySize)
243246
{
244247
// Determine the largest size after the transformation
245248
measureSize = ComputeLargestTransformedSize(availableSize);
@@ -301,7 +304,7 @@ protected override Size ArrangeOverride(Size finalSize)
301304
_layoutRoot.Arrange(finalRect);
302305

303306
// This is the first opportunity to find out the Child's true DesiredSize
304-
if (IsSizeSmaller(finalSizeTransformed, child.RenderSize) && (Size.Empty == _childActualSize))
307+
if (IsSizeSmaller(finalSizeTransformed, child.RenderSize) && (EmptySize == _childActualSize))
305308
{
306309
// Unfortunately, all the work so far is invalid because the wrong DesiredSize was used
307310
// Make a note of the actual DesiredSize
@@ -313,7 +316,7 @@ protected override Size ArrangeOverride(Size finalSize)
313316
else
314317
{
315318
// Clear the "need to measure/arrange again" flag
316-
_childActualSize = Size.Empty;
319+
_childActualSize = EmptySize;
317320
}
318321

319322
// Return result to perform the transformation
@@ -329,7 +332,7 @@ protected override Size ArrangeOverride(Size finalSize)
329332
private Size ComputeLargestTransformedSize(Size arrangeBounds)
330333
{
331334
// Computed largest transformed size
332-
Size computedSize = Size.Empty;
335+
Size computedSize = EmptySize;
333336

334337
// Detect infinite bounds and constrain the scenario
335338
bool infiniteWidth = double.IsInfinity(arrangeBounds.Width);

components/LayoutTransformControl/src/PropertyChangeEventSource.cs

Lines changed: 17 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,87 +8,47 @@ namespace CommunityToolkit.WinUI.Controls;
88
/// Allows raise an event when the value of a dependency property changes when a view model is otherwise not necessary.
99
/// </summary>
1010
/// <typeparam name="TPropertyType">Type of the DependencyProperty</typeparam>
11-
internal partial class PropertyChangeEventSource<TPropertyType> : FrameworkElement
11+
internal partial class PropertyChangeEventSource<TPropertyType>
1212
{
1313
private readonly DependencyObject _source;
14+
private readonly DependencyProperty _property;
15+
private readonly long _token;
1416

1517
/// <summary>
1618
/// Occurs when the value changes.
1719
/// </summary>
1820
public event EventHandler<TPropertyType> ValueChanged;
1921

2022
/// <summary>
21-
/// Value Dependency Property
22-
/// </summary>
23-
public static readonly DependencyProperty ValueProperty =
24-
DependencyProperty.Register(
25-
"Value",
26-
typeof(TPropertyType),
27-
typeof(PropertyChangeEventSource<TPropertyType>),
28-
new PropertyMetadata(default(TPropertyType), OnValueChanged));
29-
30-
/// <summary>
31-
/// Gets or sets the Value property. This dependency property
32-
/// indicates the value.
23+
/// Gets the Value property.
3324
/// </summary>
3425
public TPropertyType Value
3526
{
36-
get { return (TPropertyType)GetValue(ValueProperty); }
37-
set { SetValue(ValueProperty, value); }
38-
}
39-
40-
/// <summary>
41-
/// Handles changes to the Value property.
42-
/// </summary>
43-
/// <param name="d">
44-
/// The <see cref="DependencyObject"/> on which the property has changed value.
45-
/// </param>
46-
/// <param name="e">
47-
/// Event data that is issued by any event that
48-
/// tracks changes to the effective value of this property.
49-
/// </param>
50-
private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
51-
{
52-
var target = (PropertyChangeEventSource<TPropertyType>)d;
53-
TPropertyType oldValue = (TPropertyType)e.OldValue;
54-
TPropertyType newValue = target.Value;
55-
target.OnValueChanged(oldValue, newValue);
56-
}
57-
58-
/// <summary>
59-
/// Provides derived classes an opportunity to handle changes to the Value property.
60-
/// </summary>
61-
/// <param name="oldValue">The old Value value</param>
62-
/// <param name="newValue">The new Value value</param>
63-
private void OnValueChanged(TPropertyType oldValue, TPropertyType newValue)
64-
{
65-
ValueChanged?.Invoke(_source, newValue);
27+
get => (TPropertyType)_source.GetValue(_property);
28+
set => _source.SetValue(_property, value);
6629
}
6730

6831
/// <summary>
6932
/// Initializes a new instance of the <see cref="PropertyChangeEventSource{TPropertyType}"/> class.
7033
/// </summary>
7134
/// <param name="source">The source.</param>
72-
/// <param name="propertyName">Name of the property.</param>
73-
/// <param name="bindingMode">The binding mode.</param>
35+
/// <param name="property">Monitor this dependency property for changes.</param>
7436
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
7537
public PropertyChangeEventSource(
7638
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
7739
DependencyObject source,
78-
string propertyName,
79-
BindingMode bindingMode = BindingMode.TwoWay)
40+
DependencyProperty property)
8041
{
8142
_source = source;
43+
_property = property;
44+
_token = source.RegisterPropertyChangedCallback(property, (_, _) =>
45+
{
46+
ValueChanged?.Invoke(this, (TPropertyType)source.GetValue(property));
47+
});
48+
}
8249

83-
// Bind to the property to be able to get its changes relayed as events through the ValueChanged event.
84-
var binding =
85-
new Binding
86-
{
87-
Source = source,
88-
Path = new PropertyPath(propertyName),
89-
Mode = bindingMode
90-
};
91-
92-
SetBinding(ValueProperty, binding);
50+
public void Unregister()
51+
{
52+
_source.UnregisterPropertyChangedCallback(_property, _token);
9353
}
9454
}

components/Primitives/src/WrapPanel/WrapPanel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void Arrange(UIElement child, bool isLast = false)
214214
}
215215

216216
var desiredMeasure = new UvMeasure(Orientation, child.DesiredSize);
217-
if ((desiredMeasure.U + position.U + paddingEnd.U) > parentMeasure.U)
217+
if ((desiredMeasure.U + position.U + paddingEnd.U) > parentMeasure.U || position.U >= parentMeasure.U)
218218
{
219219
// next row!
220220
position.U = paddingStart.U;

0 commit comments

Comments
 (0)