Skip to content

Commit

Permalink
Merge branch 'uwp-net8-windows' into net9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Arlodotexe committed Dec 13, 2024
2 parents f03f407 + 256e78a commit 6e80763
Show file tree
Hide file tree
Showing 38 changed files with 644 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
merge_group:

env:
DOTNET_VERSION: ${{ '9.0.100' }}
DOTNET_VERSION: ${{ '9.0.x' }}
ENABLE_DIAGNOSTICS: true
MSBUILD_VERBOSITY: normal
#COREHOST_TRACE: 1
Expand Down
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<NoWarn>$(NoWarn);Uno0001</NoWarn>
<!-- TODO: Turn off sample pages needing samples for now, for initial commit -->
<NoWarn>$(NoWarn);TKSMPL0014;</NoWarn>

<!-- See https://github.com/CommunityToolkit/Windows/pull/567#issuecomment-2498739244 -->
<WarningsNotAsErrors>NU1901;NU1902;NU1903;NU1904</WarningsNotAsErrors>
</PropertyGroup>

<Import Project="Windows.Toolkit.Common.props" />
Expand Down
2 changes: 1 addition & 1 deletion GenerateAllSolution.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@ECHO OFF
SET "MultiTargets=%1"
IF "%MultiTargets%"=="" SET "MultiTargets=all"
IF "%MultiTargets%"=="" SET "MultiTargets=uwp,wasdk,wasm"

powershell .\tooling\GenerateAllSolution.ps1 -MultiTargets %MultiTargets%
9 changes: 4 additions & 5 deletions components/Behaviors/samples/InvokeActionsSample.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
xmlns:ani="using:CommunityToolkit.WinUI.Animations"
xmlns:behaviors="using:CommunityToolkit.WinUI.Behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:local="using:BehaviorsExperiment.Samples"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand All @@ -20,7 +19,7 @@
IsSequential="True">
<ani:StartAnimationActivity Animation="{Binding ElementName=FadeOutAnimation}" />
<ani:InvokeActionsActivity>
<interactions:ChangePropertyAction PropertyName="Foreground"
<interactivity:ChangePropertyAction PropertyName="Foreground"
TargetObject="{Binding ElementName=MyText}"
Value="Purple" />
<!--<mediaactions:PlaySoundAction Source="Assets/Llama.mp3"/>-->
Expand Down Expand Up @@ -53,12 +52,12 @@
</TextBlock>

<interactivity:Interaction.Behaviors>
<interactions:EventTriggerBehavior EventName="Click">
<interactions:ChangePropertyAction PropertyName="Foreground"
<interactivity:EventTriggerBehavior EventName="Click">
<interactivity:ChangePropertyAction PropertyName="Foreground"
TargetObject="{Binding ElementName=MyText}"
Value="White" />
<behaviors:StartAnimationAction Animation="{Binding ElementName=MoveAnimation}" />
</interactions:EventTriggerBehavior>
</interactivity:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Button>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviors="using:CommunityToolkit.WinUI.Behaviors"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity">

<StackPanel MaxWidth="480"
Spacing="8">
<TextBox PlaceholderText="Set the focus to this TextBox and press enter">
<interactivity:Interaction.Behaviors>
<behaviors:KeyDownTriggerBehavior Key="Enter">
<core:CallMethodAction MethodName="IncrementCount"
<interactivity:CallMethodAction MethodName="IncrementCount"
TargetObject="{x:Bind}" />
</behaviors:KeyDownTriggerBehavior>
</interactivity:Interaction.Behaviors>
Expand Down
5 changes: 2 additions & 3 deletions components/Behaviors/samples/NavigateToUriActionSample.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviors="using:CommunityToolkit.WinUI.Behaviors"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity">

<Button Content="Click to navigate">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<interactivity:EventTriggerBehavior EventName="Click">
<behaviors:NavigateToUriAction NavigateUri="https://aka.ms/toolkit/windows" />
</core:EventTriggerBehavior>
</interactivity:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Button>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
xmlns:ani="using:CommunityToolkit.WinUI.Animations"
xmlns:behaviors="using:CommunityToolkit.WinUI.Behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:local="using:BehaviorsExperiment.Samples"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand Down Expand Up @@ -55,9 +54,9 @@
</Image>

<interactivity:Interaction.Behaviors>
<interactions:EventTriggerBehavior EventName="Click">
<interactivity:EventTriggerBehavior EventName="Click">
<behaviors:StartAnimationAction Animation="{Binding ElementName=MoveAnimation}" />
</interactions:EventTriggerBehavior>
</interactivity:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Button>
</Page>
8 changes: 4 additions & 4 deletions components/Behaviors/src/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
<Project>
<!-- WinUI 2 / UWP -->
<ItemGroup Condition="'$(IsUwp)' == 'true'">
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed" Version="2.0.1"/>
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed" Version="3.0.0-preview1"/>
</ItemGroup>

<!-- WinUI 2 / Uno -->
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2'">
<PackageReference Include="Uno.Microsoft.Xaml.Behaviors.Uwp.Managed" Version="2.4.2" />
<PackageReference Include="Uno.Microsoft.Xaml.Behaviors.Interactivity" Version="3.0.0-dev.17.g7c09b9114d" />
</ItemGroup>

<!-- WinUI 3 / WinAppSdk -->
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true'">
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="3.0.0-preview1" />
</ItemGroup>

<!-- WinUI 3 / Uno -->
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3'">
<PackageReference Include="Uno.Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.4.2" />
<PackageReference Include="Uno.Microsoft.Xaml.Behaviors.Interactivity" Version="3.0.0-dev.17.g7c09b9114d" />
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions components/Converters/src/ColorToDisplayNameConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ public object Convert(
// Track https://github.com/unoplatform/uno/issues/18004
return "Not supported";
#elif WINUI2
#if NET8_0_OR_GREATER
// Following advice from Sergio0694
return color.ToString();
#else
return Windows.UI.ColorHelper.ToDisplayName(color);
#endif
#elif WINUI3
return Microsoft.UI.ColorHelper.ToDisplayName(color);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ public sealed partial class ResourceNameToResourceStringConverter : IValueConver
/// <param name="parameter">Optional parameter. Not used.</param>
/// <param name="language">The language of the conversion.</param>
/// <returns>The string corresponding to the resource name.</returns>
public object Convert(object value, Type targetType, object parameter, string language)
public object? Convert(object value, Type targetType, object parameter, string language)
{
var stringValue = value?.ToString();
if (stringValue is null)
var valueAsString = value?.ToString();
if (valueAsString == null)
{
return string.Empty;
}

#if WINAPPSDK && !HAS_UNO
return _resourceManager.MainResourceMap.TryGetValue(stringValue).ValueAsString;
return _resourceManager.MainResourceMap.TryGetValue(valueAsString).ValueAsString;
#else
return _resourceLoader.GetString(stringValue) ?? string.Empty;
return _resourceLoader.GetString(valueAsString) ?? string.Empty;
#endif
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Page x:Class="ExtensionsExperiment.Samples.DispatcherQueueExtensions.KeyboardDebounceSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">

<StackPanel Spacing="8">
<TextBox PlaceholderText="Type here..."
TextChanged="TextBox_TextChanged" />
<TextBlock x:Name="ResultText" />
</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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.

using CommunityToolkit.WinUI;
#if WINAPPSDK
using DispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue;
using DispatcherQueueTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
#else
using DispatcherQueue = Windows.System.DispatcherQueue;
using DispatcherQueueTimer = Windows.System.DispatcherQueueTimer;
#endif

namespace ExtensionsExperiment.Samples.DispatcherQueueExtensions;

[ToolkitSample(id: nameof(KeyboardDebounceSample), "DispatcherQueueTimer Debounce Keyboard", description: "A sample for showing how to use the DispatcherQueueTimer Debounce extension to smooth keyboard input.")]
[ToolkitSampleNumericOption("Interval", 120, 60, 240)]
public sealed partial class KeyboardDebounceSample : Page
{
public DispatcherQueueTimer _debounceTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();

public KeyboardDebounceSample()
{
InitializeComponent();
}

private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (sender is TextBox textBox)
{
_debounceTimer.Debounce(() =>
{
ResultText.Text = textBox.Text;
},
//// i.e. if another keyboard press comes in within 120ms of the last, we'll wait before we fire off the request
interval: TimeSpan.FromMilliseconds(Interval),
//// If we're blanking out or the first character type, we'll start filtering immediately instead to appear more responsive.
//// We want to switch back to trailing as the user types more so that we still capture all the input.
immediate: textBox.Text.Length <= 1);
}
}
}
14 changes: 14 additions & 0 deletions components/Extensions/samples/Dispatcher/MouseDebounceSample.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Page x:Class="ExtensionsExperiment.Samples.DispatcherQueueExtensions.MouseDebounceSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">

<StackPanel Spacing="8">
<Button Click="Button_Click"
Content="Click Me" />
<TextBlock x:Name="ResultText" />
</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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.

using CommunityToolkit.WinUI;
#if WINAPPSDK
using DispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue;
using DispatcherQueueTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
#else
using DispatcherQueue = Windows.System.DispatcherQueue;
using DispatcherQueueTimer = Windows.System.DispatcherQueueTimer;
#endif

namespace ExtensionsExperiment.Samples.DispatcherQueueExtensions;

[ToolkitSample(id: nameof(MouseDebounceSample), "DispatcherQueueTimer Debounce Mouse", description: "A sample for showing how to use the DispatcherQueueTimer Debounce extension to smooth mouse input.")]
[ToolkitSampleNumericOption("Interval", 400, 300, 1000)]
public sealed partial class MouseDebounceSample : Page
{
public DispatcherQueueTimer _debounceTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();

private int _count = 0;

public MouseDebounceSample()
{
InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
_debounceTimer.Debounce(() =>
{
ResultText.Text = $"You hit the button {++_count} times!";
},
interval: TimeSpan.FromMilliseconds(Interval),
// By being on the leading edge, we ignore inputs past the first for the duration of the interval
immediate: true);
}
}
42 changes: 42 additions & 0 deletions components/Extensions/samples/DispatcherQueueTimerExtensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: DispatcherQueueTimerExtensions
author: michael-hawker
description: Helpers for executing code at specific times on a UI thread through a DispatcherQueue instance with a DispatcherQueueTimer.
keywords: dispatcher, dispatcherqueue, DispatcherHelper, DispatcherQueueExtensions, DispatcherQueueTimer, DispatcherQueueTimerExtensions
dev_langs:
- csharp
category: Extensions
subcategory: Miscellaneous
discussion-id: 0
issue-id: 0
icon: Assets/Extensions.png
---

The `DispatcherQueueTimerExtensions` static class provides an extension method for [`DispatcherQueueTimer`](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.dispatching.dispatcherqueue) objects that make it easier to execute code on a specific UI thread at a specific time.

The `DispatcherQueueTimerExtensions` provides a single extension method, `Debounce`. This is a standard technique used to rate-limit input from a user to not overload requests on an underlying service or query elsewhere.

> [!WARNING]
> You should exclusively use the `DispatcherQueueTimer` instance calling `Debounce` for the purposes of Debouncing one specific action/scenario only and not configure it for other additional uses.
For each scenario that you want to Debounce, you'll want to create a separate `DispatcherQueueTimer` instance to track that specific scenario. For instance, if the below samples were both within your application. You'd need two separate timers to track debouncing both scenarios. One for the keyboard input, and a different one for the mouse input.

> [!NOTE]
> Using the `Debounce` method will set `DispatcherQueueTimer.IsRepeating` to `false` to ensure proper operation. Do not change this value.
> [!NOTE]
> If additionally registering to the `DispatcherQueueTimer.Tick` event (uncommon), it will be raised in one of two ways: 1. For a trailing debounce, it will be raised alongside the requested Action passed to the Debounce method. 2. For a leading debounce, it will be raised when the cooldown has expired and another call to Debounce would result in running the action.
## Syntax

It can be used in a number of ways, but most simply like so as a keyboard limiter:

> [!SAMPLE KeyboardDebounceSample]
Or for preventing multiple inputs from occuring accidentally (e.g. ignoring a double/multi-click):

> [!SAMPLE MouseDebounceSample]
## Examples

You can find more examples in the [unit tests](https://github.com/CommunityToolkit/Windows/blob/rel/8.1.240916/components/Extensions/tests/DispatcherQueueTimerExtensionTests.cs).
9 changes: 1 addition & 8 deletions components/Extensions/samples/ListViewExtensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ The `AlternateColor` property provides a way to assign a background color to eve
Here is how this property can be used in XAML:

```xaml
<Page ...
xmlns:ui="using:CommunityToolkit.WinUI">

<ListView
ui:ListViewExtensions.AlternateColor="Silver"
ItemsSource="{x:Bind MainViewModel.Items, Mode=OneWay}" />
```
> [!SAMPLE ListViewExtensionsAlternateColorSample]
## AlternateItemTemplate

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Page x:Class="ExtensionsExperiment.Samples.ListViewExtensionsAlternateColorSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="using:CommunityToolkit.WinUI"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<ListView ui:ListViewExtensions.AlternateColor="Silver">
<ListView.Items>
<x:String>One</x:String>
<x:String>Two</x:String>
<x:String>Three</x:String>
<x:String>Four</x:String>
<x:String>Five</x:String>
<x:String>Six</x:String>
<x:String>Seven</x:String>
<x:String>Eight</x:String>
<x:String>Nine</x:String>
<x:String>Ten</x:String>
</ListView.Items>
</ListView>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.

namespace ExtensionsExperiment.Samples;

/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
[ToolkitSample(id: nameof(ListViewExtensionsAlternateColorSample), nameof(ListViewExtensionsAlternateColorSample), description: $"A sample for showing how to use the ListViewExtensions.AlternateColor attached property.")]
public sealed partial class ListViewExtensionsAlternateColorSample : Page
{
public ListViewExtensionsAlternateColorSample()
{
this.InitializeComponent();
}
}
Loading

0 comments on commit 6e80763

Please sign in to comment.