当我对模拟器进行测试时,我的页面正常显示有问题。但是,当我在我的设备上运行它时,页面是空的!
我正在使用项目模板制作枢轴控件,在 Pivot.ItemTemplate 内我也有一个 ListBox 和 ListBox.ItemTemplate
下面的代码应生成一个标题为“PIVOT TEST”的页面,其中包含 3 个枢轴项:“枢轴 1”、“枢轴 2”、“枢轴 3”。在每个枢轴内,应该有一个列表。对于“pivot 1”,列表中应该有 3 个项目:“name 1”、“name 2”、“name 3”。对于“枢轴 2”,列表中应该有 2 个项目:“名称 1”、“名称 2”。对于“枢轴 3”,列表中应该有 1 项:“名称 1”
这是xaml:
...
<controls:Pivot x:Name="pivot" Title="PIVOT TEST">
<controls:Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding TitleText}" />
</DataTemplate>
</controls:Pivot.HeaderTemplate>
<controls:Pivot.ItemTemplate>
<DataTemplate>
<ListBox ItemsSource="{Binding List}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</controls:Pivot.ItemTemplate>
</controls:Pivot>
...
这是整个页面的代码:
public partial class PivotTest : PhoneApplicationPage {
private List<RandomObject> randomObjectList
= new List<RandomObject>();
public PivotTest() {
InitializeComponent();
randomObjectList.Add(new RandomObject() {
Name = "name 1"
});
randomObjectList.Add(new RandomObject() {
Name = "name 2"
});
randomObjectList.Add(new RandomObject() {
Name = "name 3"
});
BindPivot();
}
private void BindPivot() {
pivot.ItemsSource = new[] {
new {
TitleText = "pivot 1",
List = randomObjectList
},
new {
TitleText = "pivot 2",
List = randomObjectList.Take(2).ToList()
},
new {
TitleText = "pivot 3",
List = randomObjectList.Take(1).ToList()
}
};
}
}
我也有一类只是为了将随机数据填充到列表框中:
public class RandomObject {
public string Name { get; set; }
}
在模拟器上运行它会得到预期的结果,如下所示:
但是,当我在设备上运行它时,根本没有任何显示!它是一个空页面,唯一显示的是顶部的“PIVOT TEST”,它是枢轴控件的标题,但没有枢轴项目,并且没有列表框。
上面的代码不需要任何添加,你可以做一个测试项目,复制/粘贴上面的代码来检查。
这可能是什么原因?
提前致谢!
编辑:忘了说这是一个 Windows Phone OS 7.1 项目。我不知道这是否重要。