这是让我发疯的代码。它在 Windows 8(快照视图)上运行良好,但是当我尝试在我的 Windows Phone 7 应用程序中运行相同的 XAML 时,它不起作用。
发生了什么 应用程序运行良好,但问题是屏幕是空白的。我试图为 itemtemplate 添加一些背景,它确实出现了,这意味着数据绑定可能正在工作。但是 5 个文本块的内容没有显示。
<ListBox x:Name="result_s" Margin="0,296,0,0" HorizontalAlignment="Center" VerticalAlignment="Top">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="8,8,48,8" Orientation="Horizontal" Height="80">
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" FontSize="24" Width="auto" TextWrapping="Wrap" Margin="0,0,0,0" Text="{Binding coeff}"/>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" FontSize="24" Width="auto" TextWrapping="Wrap" Margin="4,0,0,0" Text="{Binding x}"/>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" FontSize="24" Width="auto" TextWrapping="Wrap" Margin="0,0,0,16" Text="{Binding xPow}"/>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" FontSize="24" Width="auto" TextWrapping="Wrap" Margin="4,0,0,0" Text="{Binding y}"/>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" FontSize="24" Width="auto" TextWrapping="Wrap" Margin="0,0,0,16" Text="{Binding yPow}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
这是后面的代码
void func()
{
ObservableCollection<Equation> answer = new ObservableCollection<Equation>();
// SOME CODE GOES IN HERE, THE CODE POPULATES answer
result_s.ItemsSource = null;
result_s.ItemsSource = answer;
}
拜托,你能看到这不起作用的任何原因吗?