Skip to content

Commit ec188d8

Browse files
committed
Refactored the Surface Dial extensions for TextBox
1 parent 60008a5 commit ec188d8

File tree

5 files changed

+165
-281
lines changed

5 files changed

+165
-281
lines changed

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
ui:ListViewExtensions.AlternateColor="#33AAAAAA"
2626
ui:ListViewExtensions.AlternateItemTemplate="{StaticResource AlternateTemplate}"
2727
ui:ListViewExtensions.Command="{Binding SampleCommand}"
28-
ui:ListViewExtensions.StretchItemContainerDirection="Both"
28+
ui:ListViewExtensions.ItemContainerStretchDirection="Both"
2929
IsItemClickEnabled="True"
3030
ItemTemplate="{StaticResource NormalTemplate}" />
3131
</Grid>

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/SurfaceDialTextbox/SurfaceDialTextboxCode.bind

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@
1212

1313
<TextBox HorizontalAlignment="Left"
1414
VerticalAlignment="Top"
15-
Margin="0,0,0,10"
15+
Margin="0,0,0,10"
1616
Text="0"
17-
Width="250"
18-
ui:SurfaceDialTextbox.StepValue="@[StepValue:DoubleSlider:1:0.1-10]"
19-
ui:SurfaceDialTextbox.ForceMenuItem="@[ForceMenuItem:Bool:true]"
20-
ui:SurfaceDialTextbox.EnableHapticFeedback="@[EnableHapticFeedback:Bool:true]"
21-
ui:SurfaceDialTextbox.EnableMinMaxValue="@[EnableMinMaxValue:Bool:true]"
22-
ui:SurfaceDialTextbox.MinValue="@[MinValue:DoubleSlider:0:0-100]"
23-
ui:SurfaceDialTextbox.MaxValue="@[MaxValue:DoubleSlider:100:0-100]"
24-
ui:SurfaceDialTextbox.Icon="@[Icon:Enum:RadialControllerMenuKnownIcon.Ruler]"
25-
ui:SurfaceDialTextbox.EnableTapToNextControl="@[EnableTapToNextControl:Bool:true]"/>
17+
Width="250"/>
18+
<ui:TextBoxExtensions.SurfaceDialOptions>
19+
<ui:SurfaceDialOptions
20+
StepValue="@[StepValue:DoubleSlider:1:0.1-10]"
21+
ForceMenuItem="@[ForceMenuItem:Bool:true]"
22+
EnableHapticFeedback="@[EnableHapticFeedback:Bool:true]"
23+
EnableMinMaxValue="@[EnableMinMaxValue:Bool:true]"
24+
MinValue="@[MinValue:DoubleSlider:0:0-100]"
25+
MaxValue="@[MaxValue:DoubleSlider:100:0-100]"
26+
Icon="@[Icon:Enum:RadialControllerMenuKnownIcon.Ruler]"
27+
EnableTapToNextControl="@[EnableTapToNextControl:Bool:true]"/>
28+
</ui:TextBoxExtensions.SurfaceDialOptions>
2629
</StackPanel>
2730
</Grid>
2831
</Page>

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/SurfaceDialTextbox/SurfaceDialTextboxPage.xaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@
88

99
<!-- Shallow Copy -->
1010
<Grid>
11-
<TextBox ui:TextBoxExtensions.StepValue="1.0"
12-
ui:TextBoxExtensions.ForceMenuItem="True"
13-
ui:TextBoxExtensions.EnableHapticFeedback="True"
14-
ui:TextBoxExtensions.EnableMinMaxValue="True"
15-
ui:TextBoxExtensions.MinValue="0"
16-
ui:TextBoxExtensions.MaxValue="100"
17-
ui:TextBoxExtensions.Icon="Ruler"
18-
ui:TextBoxExtensions.EnableTapToNextControl="True" />
11+
<TextBox>
12+
<ui:TextBoxExtensions.SurfaceDialOptions>
13+
<ui:SurfaceDialOptions
14+
StepValue="1.0"
15+
ForceMenuItem="True"
16+
EnableHapticFeedback="True"
17+
EnableMinMaxValue="True"
18+
MinValue="0"
19+
MaxValue="100"
20+
Icon="Ruler"
21+
EnableTapToNextControl="True"/>
22+
</ui:TextBoxExtensions.SurfaceDialOptions>
23+
</TextBox>
1924
</Grid>
2025
</Page>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 Windows.UI.Input;
6+
using Windows.UI.Xaml.Controls;
7+
8+
namespace Microsoft.Toolkit.Uwp.UI
9+
{
10+
/// <summary>
11+
/// A model containing options for configuring the Surface Dial support through <see cref="TextBoxExtensions"/>.
12+
/// </summary>
13+
public sealed class SurfaceDialOptions
14+
{
15+
/// <summary>
16+
/// Gets an internal cached instance to avoid allocations from <see cref="TextBoxExtensions"/>.
17+
/// </summary>
18+
internal static SurfaceDialOptions Default { get; } = new();
19+
20+
/// <summary>
21+
/// Gets or sets a value indicating whether new menu items shouldn't be added automatically.
22+
/// This should be set to <see langword="true"/> if you provide the <see cref="RadialController"/> yourself.
23+
/// </summary>
24+
public bool ForceMenuItem { get; set; }
25+
26+
/// <summary>
27+
/// Gets or sets the default icon of the menu item that gets added.
28+
/// A user will most likely not see this.
29+
/// Defaults to <see cref="RadialControllerMenuKnownIcon.Ruler"/>.
30+
/// </summary>
31+
public RadialControllerMenuKnownIcon Icon { get; set; } = RadialControllerMenuKnownIcon.Ruler;
32+
33+
/// <summary>
34+
/// Gets or sets the amount the <see cref="TextBox"/> will be modified for each rotation step on the Surface Dial.
35+
/// This can be any double value.
36+
/// </summary>
37+
public double StepValue { get; set; }
38+
39+
/// <summary>
40+
/// Gets or sets a value indicating whether to enable the haptic feedback when rotating the dial for the give TextBox.
41+
/// This is enabled by default.
42+
/// </summary>
43+
public bool EnableHapticFeedback { get; set; } = true;
44+
45+
/// <summary>
46+
/// Gets or sets the minimum value the <see cref="TextBox"/> can have when modifying it using a Surface Dial.
47+
/// Default is -100.0.
48+
/// </summary>
49+
public double MinValue { get; set; } = -100;
50+
51+
/// <summary>
52+
/// Gets or sets the maximum value the <see cref="TextBox"/> can have when modifying it using a Surface Dial.
53+
/// Default is 100.0.
54+
/// </summary>
55+
public double MaxValue { get; set; } = 100;
56+
57+
/// <summary>
58+
/// Gets or sets a value indicating whether to automatically try to focus the next focusable element from the Surface Dial enabled <see cref="TextBox"/>.
59+
/// This is on by default.
60+
/// </summary>
61+
public bool EnableTapToNextControl { get; set; } = true;
62+
63+
/// <summary>
64+
/// Gets or sets a value indicating whether to limit the value in the <see cref="TextBox"/> to <see cref="MinValue"/> and <see cref="MaxValue"/>.
65+
/// </summary>
66+
public bool EnableMinMaxValue { get; set; }
67+
}
68+
}

0 commit comments

Comments
 (0)