Skip to content

Commit

Permalink
fix: NullReferenceException
Browse files Browse the repository at this point in the history
  • Loading branch information
workgroupengineering committed Apr 26, 2022
1 parent b2ea50d commit 70b26dd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public WinUIDeterminateProgressRing()

private void ProgressValue_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ProgressRing.Value = double.Parse(ProgressValue.SelectedValue as string);
if (ProgressRing is { })
{
ProgressRing.Value = double.Parse(ProgressValue.SelectedValue as string);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public sealed partial class TabViewPage : Page
public TabViewPage()
{
this.InitializeComponent();
Loaded += TabViewPage_Loaded;
DisabledTab.Loaded += TabViewPage_Loaded;
_iconSource = new SymbolIconSource();
_iconSource.Symbol = Symbol.Placeholder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" TextWrapping="Wrap" x:Name="timeSince" />
<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."/>
<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"/>
</Grid>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,34 @@ public sealed partial class OrientationTests : Page
{
long lastTime;
public OrientationTests()
{
this.InitializeComponent();
{
this.InitializeComponent();
lastTime = DateTime.UtcNow.ToUnixTimeMilliseconds();
SimpleOrientationSensor.GetDefault().OrientationChanged += OnSensorOrientationChanged;
this.Loaded += (s, e) =>
{
var sensor = SimpleOrientationSensor.GetDefault();
if (sensor is { })
{
sensor.OrientationChanged += OnSensorOrientationChanged;
}
else
{
message.Text = "This device does not have an orientation sensor.";
}
};
}

private void OnSensorOrientationChanged(SimpleOrientationSensor sender, SimpleOrientationSensorOrientationChangedEventArgs args)
{
var now = DateTime.UtcNow.ToUnixTimeMilliseconds();

var diff = now - lastTime;
var s = diff / 1000;
var ms = diff % 1000;
timeSince.Text = $"~{s}.{ms} seconds since last orientation change.";
lastTime = now;
}
}

private void OnSensorOrientationChanged(SimpleOrientationSensor sender, SimpleOrientationSensorOrientationChangedEventArgs args)
{
var now = DateTime.UtcNow.ToUnixTimeMilliseconds();

var diff = now - lastTime;
var s = diff / 1000;
var ms = diff % 1000;
timeSince.Text = $"~{s}.{ms} seconds since last orientation change.";
lastTime = now;
}
}
}

0 comments on commit 70b26dd

Please sign in to comment.