Skip to content

Commit 70b26dd

Browse files
fix: NullReferenceException
1 parent b2ea50d commit 70b26dd

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/ProgressRing/WinUIDeterminateProgressRing.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ public WinUIDeterminateProgressRing()
2121

2222
private void ProgressValue_SelectionChanged(object sender, SelectionChangedEventArgs e)
2323
{
24-
ProgressRing.Value = double.Parse(ProgressValue.SelectedValue as string);
24+
if (ProgressRing is { })
25+
{
26+
ProgressRing.Value = double.Parse(ProgressValue.SelectedValue as string);
27+
}
2528
}
2629
}
2730
}

src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/TabViewTests/TabViewPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public sealed partial class TabViewPage : Page
4343
public TabViewPage()
4444
{
4545
this.InitializeComponent();
46-
Loaded += TabViewPage_Loaded;
46+
DisabledTab.Loaded += TabViewPage_Loaded;
4747
_iconSource = new SymbolIconSource();
4848
_iconSource.Symbol = Symbol.Placeholder;
4949

src/SamplesApp/UITests.Shared/Windows_Devices/OrientationTests.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
<RowDefinition Height="Auto" />
1515
</Grid.RowDefinitions>
1616
<TextBlock Grid.Row="0" TextWrapping="Wrap" x:Name="timeSince" />
17-
<TextBlock Grid.Row="1" TextWrapping="Wrap" Text="This is mainly for mobile. It should not take longer than 1 or 2 seconds for the orientation event to happen once orientation changes."/>
17+
<TextBlock Grid.Row="1" TextWrapping="Wrap" Text="This is mainly for mobile. It should not take longer than 1 or 2 seconds for the orientation event to happen once orientation changes." x:Name="message"/>
1818
</Grid>
1919
</Page>

src/SamplesApp/UITests.Shared/Windows_Devices/OrientationTests.xaml.cs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,34 @@ public sealed partial class OrientationTests : Page
1212
{
1313
long lastTime;
1414
public OrientationTests()
15-
{
16-
this.InitializeComponent();
15+
{
16+
this.InitializeComponent();
1717
lastTime = DateTime.UtcNow.ToUnixTimeMilliseconds();
18-
SimpleOrientationSensor.GetDefault().OrientationChanged += OnSensorOrientationChanged;
18+
this.Loaded += (s, e) =>
19+
{
20+
var sensor = SimpleOrientationSensor.GetDefault();
21+
if (sensor is { })
22+
{
23+
sensor.OrientationChanged += OnSensorOrientationChanged;
24+
}
25+
else
26+
{
27+
message.Text = "This device does not have an orientation sensor.";
28+
}
29+
};
1930
}
2031

21-
private void OnSensorOrientationChanged(SimpleOrientationSensor sender, SimpleOrientationSensorOrientationChangedEventArgs args)
22-
{
23-
var now = DateTime.UtcNow.ToUnixTimeMilliseconds();
2432

25-
var diff = now - lastTime;
26-
var s = diff / 1000;
27-
var ms = diff % 1000;
28-
timeSince.Text = $"~{s}.{ms} seconds since last orientation change.";
29-
lastTime = now;
30-
}
31-
}
33+
34+
private void OnSensorOrientationChanged(SimpleOrientationSensor sender, SimpleOrientationSensorOrientationChangedEventArgs args)
35+
{
36+
var now = DateTime.UtcNow.ToUnixTimeMilliseconds();
37+
38+
var diff = now - lastTime;
39+
var s = diff / 1000;
40+
var ms = diff % 1000;
41+
timeSince.Text = $"~{s}.{ms} seconds since last orientation change.";
42+
lastTime = now;
43+
}
44+
}
3245
}

0 commit comments

Comments
 (0)