【发布时间】:2016-09-22 14:53:36
【问题描述】:
我有一个FlipView,其中包含项目和项目模板。最初加载控件时,会创建三个 FlipView 项。我注意到,如果我在那之后调整窗口大小,FlipView 决定创建一个额外的第四项。为了演示这种奇怪的行为,我创建了以下小示例:
<Page
x:Class="Test.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Test"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<FlipView x:Name="items">
<FlipView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Loaded="TextBlock_Loaded"/>
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
</Grid>
这是代码隐藏:
public sealed partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
items.ItemsSource = new string[] { "Text 1", "Text 2", "Text 3", "Text 4" };
}
private void TextBlock_Loaded(object sender, RoutedEventArgs e)
{
var textBlock = sender as TextBlock;
System.Diagnostics.Debug.WriteLine(textBlock.Text);
}
}
页面加载完毕后,你会在程序输出中看到“Text 1”、“Text 2”、“Text 3”。然后,如果您在第一个项目上尝试调整窗口大小,“Text 4”也会出现在输出中。
我的问题是:为什么会发生这种情况,我能做些什么来防止它发生吗?
【问题讨论】:
标签: xaml windows-runtime uwp