Carousel Control 的 UWP Item 边距需要时间更新?

UWP Item margin of Carousel Control takes time to update?

我正在使用 Carousel 控件,其中 ItemMargin 在后端计算如下:

MainPage.xaml

 <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  x:Name ="DemoControl"
  SizeChanged="SizeChanged"
  mc:Ignorable="d">
<Grid>
<Border Margin="0">
  <controls:Carousel x:Name="CarouselControl"
              InvertPositive="True"
              ItemDepth="300"
              ItemRotationX="0"
              ItemRotationY="45"
              ItemRotationZ ="0"
              Orientation="Horizontal"
              SelectedIndex="4">
    <controls:Carousel.EasingFunction>
      <CubicEase EasingMode="EaseOut" />
    </controls:Carousel.EasingFunction>
    <controls:Carousel.ItemTemplate>
      <DataTemplate>
        <Image Width="200"
              Height="200"
              VerticalAlignment="Bottom"
              Source="{Binding Thumbnail}"
              Stretch="Uniform" />
      </DataTemplate>
    </controls:Carousel.ItemTemplate>
  </controls:Carousel>
</Border>

MainPage.xaml.cs

背后的代码
public sealed partial class MainPage
{
   private void SizeChanged(object sender, SizeChangedEventArgs e)
    {
        this.UpdateMargin();
    }
    private void UpdateMargin()
    {
            this.DemoControl.ItemMargin = 500;
    }
 }

我注意到,当页面第一次加载时,对象会更近,但滑动控件后,距离会增加,然后保持不变。 ItemMargin 在这里更新需要一些时间吗?

UWP Item margin of Carousel Control takes time to update?

在测试过程中,轮播的边距可以在页面第一次加载后正确呈现。我们无法预生产您的问题。但是我在 SizeChanged 页中发现了你的 UpdateMargin。 Carousel loaded 事件还没有触发。我想它会出现上述问题。一般来说,如果你想更新 ItemMargin 属性,我们建议你把它放在 Carousel loaded 事件中。

private void CarouselControl_Loaded(object sender, RoutedEventArgs e)
{
    UpdateMargin();
}

这可以确保 ItemMargin 属性 可用。