Skip to content

Commit 0addc9b

Browse files
authored
Merge branch 'master' into sampleAppMediaFix
2 parents 934706a + ad1aaa6 commit 0addc9b

File tree

123 files changed

+2616
-1650
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+2616
-1650
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
// This extension is restricted to the .NET 5 because it shares the same BCL
6+
// across all targets, ensuring that the layout of our Nullable<T> mapping type
7+
// will be correct. Exposing this API on older targets (especially .NET Standard)
8+
// is not guaranteed to be correct and could result in invalid memory accesses.
9+
#if NET5_0
10+
11+
using System;
12+
using System.Runtime.CompilerServices;
13+
14+
namespace Microsoft.Toolkit.HighPerformance.Extensions
15+
{
16+
/// <summary>
17+
/// Helpers for working with the <see cref="Nullable{T}"/> type.
18+
/// </summary>
19+
public static class NullableExtensions
20+
{
21+
/// <summary>
22+
/// Returns a reference to the value of the input <see cref="Nullable{T}"/> instance, regardless of whether
23+
/// the <see cref="Nullable{T}.HasValue"/> property is returning <see langword="true"/> or not. If that is not
24+
/// the case, this method will still return a reference to the underlying <see langword="default"/> value.
25+
/// </summary>
26+
/// <typeparam name="T">The type of the underlying value</typeparam>
27+
/// <param name="value">The <see cref="Nullable{T}"/></param>
28+
/// <returns>A reference to the underlying value from the input <see cref="Nullable{T}"/> instance.</returns>
29+
/// <remarks>
30+
/// Note that attempting to mutate the returned reference will not change the value returned by <see cref="Nullable{T}.HasValue"/>.
31+
/// That means that reassigning the value of an empty instance will not make <see cref="Nullable{T}.HasValue"/> return <see langword="true"/>.
32+
/// </remarks>
33+
public static ref T DangerousGetValueOrDefaultReference<T>(this ref T? value)
34+
where T : struct
35+
{
36+
return ref Unsafe.As<T?, RawNullableData<T>>(ref value).Value;
37+
}
38+
39+
/// <summary>
40+
/// Mapping type that reflects the internal layout of the <see cref="Nullable{T}"/> type.
41+
/// See https://github.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/Nullable.cs.
42+
/// </summary>
43+
/// <typeparam name="T">The value type wrapped by the current instance.</typeparam>
44+
private struct RawNullableData<T>
45+
where T : struct
46+
{
47+
#pragma warning disable CS0649 // Unassigned fields
48+
public bool HasValue;
49+
public T Value;
50+
#pragma warning restore CS0649
51+
}
52+
}
53+
}
54+
55+
#endif

Microsoft.Toolkit.Uwp.DeveloperTools/FocusTracker/FocusTracker.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Linq;
88
using System.Text;
99
using System.Threading.Tasks;
10+
using Windows.System;
1011
using Windows.UI.Xaml;
1112
using Windows.UI.Xaml.Automation;
1213
using Windows.UI.Xaml.Controls;
@@ -45,7 +46,7 @@ private static void OnIsActiveChanged(DependencyObject d, DependencyPropertyChan
4546
}
4647
}
4748

48-
private DispatcherTimer updateTimer;
49+
private DispatcherQueueTimer updateTimer;
4950
private TextBlock controlName;
5051
private TextBlock controlType;
5152
private TextBlock controlAutomationName;
@@ -72,7 +73,7 @@ private void Start()
7273
{
7374
if (updateTimer == null)
7475
{
75-
updateTimer = new DispatcherTimer();
76+
updateTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
7677
updateTimer.Tick += UpdateTimer_Tick;
7778
}
7879

Microsoft.Toolkit.Uwp.Input.GazeInteraction/GazePointer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Windows.Devices.Input.Preview;
1212
using Windows.Foundation;
1313
using Windows.Foundation.Collections;
14+
using Windows.System;
1415
using Windows.UI;
1516
using Windows.UI.Core;
1617
using Windows.UI.Xaml;
@@ -354,7 +355,7 @@ private GazePointer()
354355
_gazeCursor = new GazeCursor();
355356

356357
// timer that gets called back if there gaze samples haven't been received in a while
357-
_eyesOffTimer = new DispatcherTimer();
358+
_eyesOffTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
358359
_eyesOffTimer.Tick += OnEyesOff;
359360

360361
// provide a default of GAZE_IDLE_TIME microseconds to fire eyes off
@@ -860,7 +861,7 @@ private void OnDeviceRemoved(GazeDeviceWatcherPreview sender, GazeDeviceWatcherR
860861

861862
private readonly List<int> _roots = new List<int>();
862863

863-
private readonly DispatcherTimer _eyesOffTimer;
864+
private readonly DispatcherQueueTimer _eyesOffTimer;
864865

865866
private readonly GazeCursor _gazeCursor;
866867

Microsoft.Toolkit.Uwp.SampleApp/Data/PhotoDataItem.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@ public class PhotoDataItem
1111
public string Category { get; set; }
1212

1313
public string Thumbnail { get; set; }
14+
15+
public override string ToString()
16+
{
17+
return Title;
18+
}
1419
}
1520
}

Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@
272272
<Content Include="Icons\More.png" />
273273
<Content Include="Icons\Notifications.png" />
274274
<Content Include="Icons\Services.png" />
275+
<Content Include="SamplePages\Primitives\SwitchPresenter.png" />
275276
<Content Include="SamplePages\TabbedCommandBar\TabbedCommandBar.png" />
276277
<Content Include="SamplePages\Animations\Effects\FadeBehavior.png" />
277278
<Content Include="SamplePages\ColorPicker\ColorPicker.png" />
@@ -495,6 +496,8 @@
495496
<Compile Include="SamplePages\ColorPicker\ColorPickerPage.xaml.cs">
496497
<DependentUpon>ColorPickerPage.xaml</DependentUpon>
497498
</Compile>
499+
<Compile Include="SamplePages\EnumValuesExtension\Animal.cs" />
500+
<Compile Include="SamplePages\EnumValuesExtension\AnimalToColorConverter.xaml.cs" />
498501
<Compile Include="SamplePages\EnumValuesExtension\EnumValuesExtensionPage.xaml.cs">
499502
<DependentUpon>EnumValuesExtensionPage.xaml</DependentUpon>
500503
</Compile>
@@ -614,6 +617,8 @@
614617
<Content Include="SamplePages\Animations\Behaviors\RotateBehaviorXaml.bind" />
615618
<Content Include="SamplePages\Animations\Effects\EffectAnimations.bind" />
616619
<Content Include="SamplePages\VisualEffectFactory\VisualEffectFactory.bind" />
620+
<Content Include="SamplePages\Animations\Activities\InvokeActionsActivityCode.bind" />
621+
<Content Include="SamplePages\Animations\Activities\StartAnimationActivityCode.bind" />
617622
</ItemGroup>
618623
<ItemGroup>
619624
<Compile Include="App.xaml.cs">
@@ -974,6 +979,9 @@
974979
<SubType>Designer</SubType>
975980
<Generator>MSBuild:Compile</Generator>
976981
</Page>
982+
<Content Include="SamplePages\Primitives\SwitchPresenter.bind">
983+
<SubType>Designer</SubType>
984+
</Content>
977985
<Page Include="SamplePages\TilesBrush\TilesBrushPage.xaml">
978986
<Generator>MSBuild:Compile</Generator>
979987
<SubType>Designer</SubType>

Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Text.Json.Serialization;
1717
using System.Text.RegularExpressions;
1818
using System.Threading.Tasks;
19+
1920
// TODO Reintroduce graph controls
2021
// using Microsoft.Toolkit.Graph.Converters;
2122
// using Microsoft.Toolkit.Graph.Providers;

Microsoft.Toolkit.Uwp.SampleApp/Pages/About.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
Grid.Column="1"
159159
animations:Implicit.Animations="{StaticResource ImplicitOffset}">
160160
<StackPanel>
161-
<TextBlock Style="{StaticResource AboutPageHeader}">Recent Activity</TextBlock>
161+
<TextBlock Style="{StaticResource AboutPageHeader}" Text="Recent Activity"/>
162162

163163
<Grid Margin="0,16,0,0">
164164
<TextBlock FontFamily="Segoe UI"
@@ -195,7 +195,7 @@
195195

196196
<StackPanel x:Name="ReleaseNotesPanel"
197197
animations:Implicit.Animations="{StaticResource ImplicitOffset}">
198-
<TextBlock Style="{StaticResource AboutPageHeader}">Release Notes</TextBlock>
198+
<TextBlock Style="{StaticResource AboutPageHeader}" Text="Release Notes"/>
199199
<ItemsControl Margin="0,16,0,0"
200200
ItemTemplate="{StaticResource ReleaseNoteTemplate}"
201201
ItemsSource="{x:Bind GitHubReleases, Mode=OneWay}" />
@@ -254,7 +254,7 @@
254254
animations:Implicit.Animations="{StaticResource ImplicitOffset}"
255255
NavigateUri="https://go.microsoft.com/fwlink/?LinkId=521839"
256256
Style="{StaticResource AboutHyperlinkButtonStyle}">
257-
<TextBlock>Privacy statement</TextBlock>
257+
<TextBlock Text="Privacy statement"/>
258258
</HyperlinkButton>
259259
</Grid>
260260
</ScrollViewer>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.Toolkit.Uwp.UI.Animations;
2+
3+
// Fade out the TextBlock
4+
await AnimationBuilder
5+
.Create()
6+
.Opacity(from: 1, to: 0, duration: TimeSpan.FromSeconds(1), easingType: EasingType.Linear)
7+
.StartAsync(MyText);
8+
9+
// Change the text and the sound here...
10+
11+
// Fade the TextBlock back in
12+
await AnimationBuilder
13+
.Create()
14+
.Opacity(to: 1, duration: TimeSpan.FromSeconds(1), easingType: EasingType.Linear)
15+
.StartAsync(MyText);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Microsoft.Toolkit.Uwp.UI.Animations;
2+
3+
// Move the button down and then back up
4+
AnimationBuilder
5+
.Create()
6+
.Translation(Axis.Y).TimedKeyFrames(b => b
7+
.KeyFrame(TimeSpan.Zero, 0)
8+
.KeyFrame(TimeSpan.FromSeconds(3), 32, EasingType.Linear)
9+
.KeyFrame(TimeSpan.FromSeconds(9), 32, EasingType.Linear)
10+
.KeyFrame(TimeSpan.FromSeconds(12), 0, EasingType.Linear))
11+
.Start(MyButton);
12+
13+
// Fade the image out and then back in
14+
AnimationBuilder
15+
.Create()
16+
.Opacity().TimedKeyFrames(
17+
delay: TimeSpan.FromSeconds(3),
18+
build: b => b
19+
.KeyFrame(TimeSpan.Zero, 1)
20+
.KeyFrame(TimeSpan.FromSeconds(3), 0, EasingType.Linear)
21+
.KeyFrame(TimeSpan.FromSeconds(6), 1, EasingType.Linear))
22+
.Start(MyImage);
23+
24+
// Alternatively, a simpler but less efficient solution involves separate animations
25+
await AnimationBuilder
26+
.Create()
27+
.Translation(Axis.Y, to: 32, duration: TimeSpan.FromSeconds(3), easingType: EasingType.Linear)
28+
.StartAsync(MyButton);
29+
await AnimationBuilder
30+
.Create()
31+
.Opacity(to: 0, duration: TimeSpan.FromSeconds(3), easingType: EasingType.Linear)
32+
.StartAsync(MyImage);
33+
await AnimationBuilder
34+
.Create()
35+
.Opacity(to: 1, duration: TimeSpan.FromSeconds(3), easingType: EasingType.Linear)
36+
.StartAsync(MyImage);
37+
await AnimationBuilder
38+
.Create()
39+
.Translation(Axis.Y, to: 0, duration: TimeSpan.FromSeconds(3), easingType: EasingType.Linear)
40+
.StartAsync(MyButton);

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/CameraHelper/CameraHelperPage.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
<ComboBox x:Name="FrameSourceGroupCombo" Header="Frame Source Group" HorizontalAlignment="Left" Width="Auto">
1818
<ComboBox.ItemTemplate>
1919
<DataTemplate>
20-
<TextBlock Text="{Binding DisplayName}"></TextBlock>
20+
<TextBlock Text="{Binding DisplayName}"/>
2121
</DataTemplate>
2222
</ComboBox.ItemTemplate>
2323
</ComboBox>
24-
<TextBlock x:Name="CameraErrorTextBlock" Style="{StaticResource ErrorMessageStyle}" Margin="0,0,0,10" Visibility="Collapsed"></TextBlock>
24+
<TextBlock x:Name="CameraErrorTextBlock" Style="{StaticResource ErrorMessageStyle}" Margin="0,0,0,10" Visibility="Collapsed"/>
2525
<Button x:Name="CaptureButton" Content="Capture Video Frame" Margin="0,10" Click="CaptureButton_Click"></Button>
2626
<Image x:Name="CurrentFrameImage" MinWidth="300" Width="400" HorizontalAlignment="Left"></Image>
2727
</StackPanel>

0 commit comments

Comments
 (0)