转盘控制的UWP项目余量需要时间更新吗



我使用的是一个旋转木马控件,其中ItemMargin在后端计算如下:

主页.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项目边距需要时间更新吗?

在测试过程中,转盘的边距可以在首次加载页面后呈现正确。我们无法预先提出你的问题。然而,我发现当你的UpdateMargin在第SizeChanged页。转盘加载事件尚未触发。我想这将是上述问题的情况。通常,如果您想更新ItemMargin属性,我们建议您将其放置在Carousel加载的事件中。

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

这可以确保ItemMargin属性可用。

最新更新