我在MainPage.xaml中放置了一个Progress Bar
控件。应用程序类型为Pivot
。
出于某种原因,我放置在Progress Bar
和TextBlock
下的PivotItem
和 a Grid
未显示。这两个控件正下方有一个LongListSelector
。这两个控件是否因此没有显示?无论如何,我使用UI将LongListSelector
拖到了下面,所以我不确定它为什么没有显示。
这是XAML:
<phone:Pivot Title="Title" Background="White" Foreground="Black">
<!--Pivot item one-->
<phone:PivotItem Header="Header" Foreground="Black">
<Grid>
<ProgressBar Name="progressBar" Value="0" IsIndeterminate="True" Margin="0,0,0,579"/>
<TextBlock Name="txtLastUpdated" FontWeight="Black" FontStyle="Italic" Foreground="Black" Margin="0,24,0,541" />
<phone:LongListSelector Name="llsLocations" ItemsSource="{Binding}" SelectionChanged="LongListSelector_OnSelectionChanged" Margin="0,62,0,0">
<phone:LongListSelector.ItemTemplate>
...
...
...
如您所见,LongListSelector
控件内部的Grid
上方有一个ProgressBar和一个TextBlock。
为什么没有显示这两个控件的任何想法?
答案 0 :(得分:3)
我认为保证金或物品定位有问题。我已经测试了以下代码并且可以运行:
<phone:Pivot Title="Title" Background="White" Foreground="Black">
<!--Pivot item one-->
<phone:PivotItem Header="Header" Foreground="Black">
<Grid>
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<ProgressBar Name="progressBar" Value="0" IsIndeterminate="True" VerticalAlignment="Center" Margin="0"/>
<TextBlock Name="txtLastUpdated" FontWeight="Black" FontStyle="Italic" Foreground="Black"
HorizontalAlignment="Center" Text="Something"/>
</StackPanel>
<phone:LongListSelector Name="llsLocations" ItemsSource="{Binding}" SelectionChanged="LongListSelector_OnSelectionChanged" Margin="0,62,0,0"/>
</Grid>
</phone:PivotItem>
</phone:Pivot>
答案 1 :(得分:1)
Remove margin of all child element of StackPanel. This will defiantly helps you.
<phone:Pivot Title="Title" Background="White" Foreground="Black">
<!--Pivot item one-->
<phone:PivotItem Header="Header" Foreground="Black">
<Grid>
<StackPanel>
<ProgressBar Name="progressBar" Value="0" IsIndeterminate="True"/>
<TextBlock Name="txtLastUpdated" FontWeight="Black" FontStyle="Italic" Foreground="Black" />
<phone:LongListSelector Name="llsLocations" ItemsSource="{Binding}" SelectionChanged="LongListSelector_OnSelectionChanged" >
<phone:LongListSelector.ItemTemplate>
</StackPanel>
</Grid>
</phone:PivotItem>
</<phone:Pivot>
答案 2 :(得分:1)
硬编码控件的位置(特别是通过拖动设计器中的控件)不是一个好习惯。尝试为Grid定义行,然后为Grid内的控件指定Grid.Row。有了它,您可以更整洁地安排网格内容。检查此link以获取有关Grid内部布局控件的更多示例和说明。以下是您的情况的示例:
<phone:PivotItem Header="Header" Foreground="Black">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<ProgressBar Name="progressBar" Value="0" IsIndeterminate="True" />
<TextBlock Name="txtLastUpdated" FontWeight="Black" FontStyle="Italic" Foreground="Black" />
</StackPanel>
<phone:LongListSelector Grid.Row="1" Name="llsLocations" ItemsSource="{Binding}" SelectionChanged="LongListSelector_OnSelectionChanged" >
<phone:LongListSelector.ItemTemplate>
...
...