Skip to content

Commit eb0c096

Browse files
committed
Fixed a crash with the items list animations
1 parent 5f87b23 commit eb0c096

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

Microsoft.Toolkit.Uwp.SampleApp/Shell.SamplePicker.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,25 +230,29 @@ private void ContainerItem_Loaded(object sender, RoutedEventArgs e)
230230

231231
private void ItemContainer_PointerExited(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
232232
{
233-
var panel = (sender as FrameworkElement).FindDescendant<DropShadowPanel>();
234-
if (panel != null)
233+
if ((sender as FrameworkElement)?.FindDescendant<DropShadowPanel>() is FrameworkElement panel)
235234
{
236235
AnimationBuilder.Create().Opacity(0, duration: TimeSpan.FromMilliseconds(1200)).Start(panel);
237-
AnimationBuilder.Create().Scale(1, duration: TimeSpan.FromMilliseconds(1200)).Start((UIElement)panel.Parent);
236+
237+
if (panel.Parent is UIElement parent)
238+
{
239+
AnimationBuilder.Create().Scale(1, duration: TimeSpan.FromMilliseconds(1200)).Start(parent);
240+
}
238241
}
239242
}
240243

241244
private void ItemContainer_PointerEntered(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
242245
{
243-
if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
246+
if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse &&
247+
(sender as FrameworkElement)?.FindDescendant<DropShadowPanel>() is FrameworkElement panel)
244248
{
245-
var panel = (sender as FrameworkElement).FindDescendant<DropShadowPanel>();
246-
if (panel != null)
247-
{
248-
panel.Visibility = Visibility.Visible;
249+
panel.Visibility = Visibility.Visible;
250+
251+
AnimationBuilder.Create().Opacity(1, duration: TimeSpan.FromMilliseconds(600)).Start(panel);
249252

250-
AnimationBuilder.Create().Opacity(1, duration: TimeSpan.FromMilliseconds(600)).Start(panel);
251-
AnimationBuilder.Create().Scale(1.1, duration: TimeSpan.FromMilliseconds(600)).Start((UIElement)panel.Parent);
253+
if (panel.Parent is UIElement parent)
254+
{
255+
AnimationBuilder.Create().Scale(1.1, duration: TimeSpan.FromMilliseconds(600)).Start(parent);
252256
}
253257
}
254258
}

0 commit comments

Comments
 (0)