Skip to content

Commit 1035ff9

Browse files
Fixes #388 SizerBase Orientation Property
Removes Mouse Extension from XAML Template and does in code-behind as to remove the need to set the Cursor property directly via binding By setting the Cursor DependencyProperty we were losing our detection mechanism, now if it's set it's an explicit override, otherwise we use our logic based on Orientation property Also, switches to new CommunityToolkit.*.Extensions Dependency vs. old copies of Tree helpers Fixes some doc typos Bumps version, tested on UWP, WASDK, and Uno.UI/WASM
1 parent 26be61d commit 1035ff9

12 files changed

+51
-474
lines changed

components/SizerBase/src/CommunityToolkit.Labs.WinUI.SizerBase.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<ToolkitComponentName>SizerBase</ToolkitComponentName>
44
<Description>This package contains SizerBase.</Description>
5-
<Version>0.0.4</Version>
5+
<Version>0.0.5</Version>
66

77
<!-- Rns suffix is required for namespaces shared across projects. See https://github.com/CommunityToolkit/Labs-Windows/issues/152 -->
88
<RootNamespace>CommunityToolkit.Labs.WinUI.SizerBaseRns</RootNamespace>

components/SizerBase/src/ContentSizer/ContentSizer.Events.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using CommunityToolkit.Labs.WinUI.SizerBaseLocal;
5+
using CommunityToolkit.WinUI;
66

77
namespace CommunityToolkit.Labs.WinUI;
88

components/SizerBase/src/Dependencies.props

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,13 @@
99
For UWP / WinAppSDK / Uno packages, place the package references here.
1010
-->
1111
<Project>
12-
<!-- WinUI 2 / UWP -->
13-
<ItemGroup Condition="'$(IsUwp)' == 'true'">
14-
<!-- <PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.2"/> -->
15-
</ItemGroup>
12+
<!-- WinUI 2 / UWP / Uno -->
13+
<ItemGroup Condition="'$(IsUwp)' == 'true' OR ('$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2')">
14+
<PackageReference Include="CommunityToolkit.Uwp.Extensions" Version="8.0.0-beta.1"/>
15+
</ItemGroup>
1616

17-
<!-- WinUI 2 / Uno -->
18-
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2'">
19-
<!-- <PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.11"/> -->
20-
</ItemGroup>
21-
22-
<!-- WinUI 3 / WinAppSdk -->
23-
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true'">
24-
<!-- <PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.2"/> -->
25-
</ItemGroup>
26-
27-
<!-- WinUI 3 / Uno -->
28-
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3'">
29-
<!-- <PackageReference Include="Uno.CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.100-dev.15.g12261e2626"/> -->
30-
</ItemGroup>
17+
<!-- WinUI 3 / WinAppSdk / Uno -->
18+
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true' OR ('$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3')">
19+
<PackageReference Include="CommunityToolkit.WinUI.Extensions" Version="8.0.0-beta.1"/>
20+
</ItemGroup>
3121
</Project>

components/SizerBase/src/SizerBase.Events.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected override void OnManipulationStarting(ManipulationStartingRoutedEventAr
7272
/// <inheritdoc />
7373
protected override void OnManipulationDelta(ManipulationDeltaRoutedEventArgs e)
7474
{
75-
// We use Trancate here to provide 'snapping' points with the DragIncrement property
75+
// We use Truncate here to provide 'snapping' points with the DragIncrement property
7676
// It works for both our negative and positive values, as otherwise we'd need to use
7777
// Ceiling when negative and Floor when positive to maintain the correct behavior.
7878
var horizontalChange =

components/SizerBase/src/SizerBase.Properties.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using CommunityToolkit.WinUI;
6+
57
#if !WINAPPSDK
68
using CursorEnum = Windows.UI.Core.CoreCursorType;
79
#else
@@ -17,7 +19,7 @@ namespace CommunityToolkit.Labs.WinUI;
1719
public partial class SizerBase : Control
1820
{
1921
/// <summary>
20-
/// Gets or sets the cursor to use when hovering over the gripper bar. If left as <c>null</c>, the control will manage the cursor automatically based on the <see cref="Orientation"/> property value.
22+
/// Gets or sets the cursor to use when hovering over the gripper bar. If left as <c>null</c>, the control will manage the cursor automatically based on the <see cref="Orientation"/> property value (default).
2123
/// </summary>
2224
public CursorEnum Cursor
2325
{
@@ -32,13 +34,13 @@ public CursorEnum Cursor
3234
DependencyProperty.Register(nameof(Cursor), typeof(CursorEnum), typeof(SizerBase), new PropertyMetadata(null, OnOrientationPropertyChanged));
3335

3436
/// <summary>
35-
/// Gets or sets the incremental amount of change for draging with the mouse or touch of a sizer control. Effectively a snapping increment for changes. The default is 1.
37+
/// Gets or sets the incremental amount of change for dragging with the mouse or touch of a sizer control. Effectively a snapping increment for changes. The default is 1.
3638
/// </summary>
3739
/// <example>
3840
/// For instance, if the DragIncrement is set to 16. Then when a component is resized with the sizer, it will only increase or decrease in size in that increment. I.e. -16, 0, 16, 32, 48, etc...
3941
/// </example>
4042
/// <remarks>
41-
/// This value is indepedent of the <see cref="KeyboardIncrement"/> property. If you need to provide consistent snapping when moving regardless of input device, set these properties to the same value.
43+
/// This value is independent of the <see cref="KeyboardIncrement"/> property. If you need to provide consistent snapping when moving regardless of input device, set these properties to the same value.
4244
/// </remarks>
4345
public double DragIncrement
4446
{
@@ -92,35 +94,38 @@ private static void OnOrientationPropertyChanged(DependencyObject d, DependencyP
9294
{
9395
if (d is SizerBase gripper)
9496
{
95-
CursorEnum cursorToUse = gripper.Orientation == Orientation.Vertical ? CursorEnum.SizeWestEast : CursorEnum.SizeNorthSouth;
97+
CursorEnum cursorByOrientation = gripper.Orientation == Orientation.Vertical ? CursorEnum.SizeWestEast : CursorEnum.SizeNorthSouth;
9698

9799
// See if there's been a cursor override, otherwise we'll pick
98100
var cursor = gripper.ReadLocalValue(CursorProperty);
99101
if (cursor == DependencyProperty.UnsetValue || cursor == null)
100102
{
101-
cursor = cursorToUse;
102-
103-
// On UWP, we use the extension in XAML to control this behavior,
104-
// so we'll update it here (and maintain binding).
105-
// We'll keep it in-sync to maintain behavior for WinUI 3 as well.
106-
gripper.SetValue(CursorProperty, cursor);
103+
cursor = cursorByOrientation;
104+
}
107105

108-
// We return here, as the Cursor will trigger this function again anyway to set for WinUI 3
109-
return;
106+
#if !WINAPPSDK
107+
// On UWP, we use our XAML extension to control this behavior,
108+
// so we'll update it here (and maintain any cursor override).
109+
if (cursor is CursorEnum cursorValue)
110+
{
111+
FrameworkElementExtensions.SetCursor(gripper, cursorValue);
110112
}
111113

114+
return;
115+
#endif
116+
112117
// TODO: [UNO] Only supported on certain platforms
113118
// See ProtectedCursor here: https://github.com/unoplatform/uno/blob/3fe3862b270b99dbec4d830b547942af61b1a1d9/src/Uno.UI/UI/Xaml/UIElement.cs#L1015-L1023
114119
#if WINAPPSDK && !HAS_UNO
115120
// Need to wait until we're at least applying template step of loading before setting Cursor
116121
// See https://github.com/microsoft/microsoft-ui-xaml/issues/7062
117-
if (gripper._applyingTemplate &&
118-
cursor is CursorEnum cursorToSet &&
122+
if (gripper._appliedTemplate &&
123+
cursor is CursorEnum cursorValue &&
119124
(gripper.ProtectedCursor == null ||
120125
(gripper.ProtectedCursor is InputSystemCursor current &&
121-
current.CursorShape != cursorToSet)))
126+
current.CursorShape != cursorValue)))
122127
{
123-
gripper.ProtectedCursor = InputSystemCursor.Create(cursorToSet);
128+
gripper.ProtectedCursor = InputSystemCursor.Create(cursorValue);
124129
}
125130
#endif
126131
}

components/SizerBase/src/SizerBase.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected virtual void OnLoaded(RoutedEventArgs e)
2121

2222
/// <summary>
2323
/// Called when the <see cref="SizerBase"/> control starts to be dragged by the user.
24-
/// Implementor should record current state of manipulated target at this point in time.
24+
/// Implementer should record current state of manipulated target at this point in time.
2525
/// They will receive the cumulative change in <see cref="OnDragHorizontal(double)"/> or
2626
/// <see cref="OnDragVertical(double)"/> based on the <see cref="Orientation"/> property.
2727
/// </summary>
@@ -42,7 +42,7 @@ protected virtual void OnLoaded(RoutedEventArgs e)
4242
/// manipulation. This method will be used regardless of input device. It will already
4343
/// be adjusted for RightToLeft <see cref="FlowDirection"/> of the containing
4444
/// layout/settings. It will also already account for any settings such as
45-
/// <see cref="DragIncrement"/> or <see cref="KeyboardIncrement"/>. The implementor
45+
/// <see cref="DragIncrement"/> or <see cref="KeyboardIncrement"/>. The implementer
4646
/// just needs to use the provided value to manipulate their baseline stored
4747
/// in <see cref="OnDragStarting"/> to provide the desired change.
4848
/// </remarks>
@@ -57,7 +57,7 @@ protected virtual void OnLoaded(RoutedEventArgs e)
5757
/// The value provided here is the cumulative change from the beginning of the
5858
/// manipulation. This method will be used regardless of input device. It will also
5959
/// already account for any settings such as <see cref="DragIncrement"/> or
60-
/// <see cref="KeyboardIncrement"/>. The implementor just needs
60+
/// <see cref="KeyboardIncrement"/>. The implementer just needs
6161
/// to use the provided value to manipulate their baseline stored
6262
/// in <see cref="OnDragStarting"/> to provide the desired change.
6363
/// </remarks>
@@ -83,7 +83,7 @@ protected override AutomationPeer OnCreateAutomationPeer()
8383
// On Uno the ProtectedCursor isn't supported yet, so we don't need this value.
8484
#if WINAPPSDK && !HAS_UNO
8585
// Used to track when we're in the OnApplyTemplateStep to change ProtectedCursor value.
86-
private bool _applyingTemplate = false;
86+
private bool _appliedTemplate = false;
8787
#endif
8888

8989
/// <inheritdoc/>
@@ -115,9 +115,9 @@ protected override void OnApplyTemplate()
115115
SizerBase_IsEnabledChanged(this, null!);
116116
#if WINAPPSDK && !HAS_UNO
117117
// On WinAppSDK, we'll trigger this to setup the initial ProtectedCursor value.
118-
_applyingTemplate = true;
118+
_appliedTemplate = true;
119119
#endif
120-
// On UWP, we'll check the current Orientation and set the Cursor property to use here still.
120+
// Ensure we have the proper cursor value setup, as we can only set now for WinUI 3
121121
OnOrientationPropertyChanged(this, null!);
122122
}
123123

components/SizerBase/src/SizerBase.xaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
1+
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
22
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:controls="using:CommunityToolkit.Labs.WinUI"
@@ -49,7 +49,6 @@
4949
<Setter.Value>
5050
<ControlTemplate TargetType="controls:SizerBase">
5151
<Grid x:Name="RootGrid"
52-
local:FrameworkElementExtensions.Cursor="{TemplateBinding Cursor}"
5352
Background="{TemplateBinding Background}">
5453

5554
<!-- Note: These align with Thumb -->

0 commit comments

Comments
 (0)