【问题标题】:WP8 Progress Bar Not RenderingWP8 进度条不呈现
【发布时间】:2013-12-30 21:02:54
【问题描述】:

我在 MainPage.xaml 中放置了一个Progress Bar 控件。应用类型为Pivot

由于某种原因,我放置在PivotItemGrid 下方的Progress Bar TextBlock 没有显示。这两个控件正下方有一个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 上方有一个 ProgressBar 和一个 TextBlock,它们也在 Grid 控件内。

任何想法为什么这两个控件没有显示?

【问题讨论】:

  • 您可以尝试在没有文本块和 LLS 的情况下使用进度条吗?

标签: windows-phone-8 grid progress-bar longlistselector


【解决方案1】:

我认为您的 Margin 或项目定位有问题。我已经测试了下面的代码,它可以工作:

<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>

【讨论】:

    【解决方案2】:
    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>
    

    【讨论】:

      【解决方案3】:

      硬编码控件的位置(尤其是通过在设计器中拖动控件)不是一个好习惯。尝试为您的 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>
              ...
              ...
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-14
        • 1970-01-01
        • 2020-03-25
        • 1970-01-01
        相关资源
        最近更新 更多