2011-12-28 61 views
1

我試圖在應用程序獲取數據時在Windows Phone 7應用程序中顯示ProgressBar。Windows Phone 7上的ProgressBar未顯示

這是我的XAML:

 <!--Panorama item one--> 
     <controls:PanoramaItem Header="headlines">    
      <Grid> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="220" /> 
        <ColumnDefinition Width="200" /> 
       </Grid.ColumnDefinitions> 
       <Button Name="refresh" Margin="320,-630,0,0" Grid.ColumnSpan="2" Height="75" Width="75" BorderThickness="0" Click="refresh_Click"> 
        <Button.Foreground> 
         <ImageBrush ImageSource="/DataCollector.Tone;component/Resources/refresh-pressed.png" /> 
        </Button.Foreground> 
        <Button.Background> 
         <ImageBrush ImageSource="/DataCollector.Tone;component/Resources/refresh.png" /> 
        </Button.Background> 
       </Button> 
       <TextBlock Text="from heraldsun" Margin="12,-30,0,0" Style="{StaticResource PhoneTextSubtleStyle}" Grid.ColumnSpan="2"></TextBlock> 
       <ProgressBar 
        Margin="0,-40,0,0" 
        x:Name="progressBar" 
        IsIndeterminate="true" 
        Visibility="Visible" Grid.ColumnSpan="2" /> 
       <ListBox Name="headlines" Margin="0,10,-12,0" ItemsSource="{Binding Tones}" Visibility="Collapsed" Grid.ColumnSpan="2"> 
        <ListBox.ItemTemplate> 
         <DataTemplate> 
          <StackPanel Orientation="Horizontal" Margin="0,17,0,17"> 
           <!--Replace rectangle with image--> 
           <Image Source="{Binding ImageUrl}" Height="75" Width="100" Margin="12,10,9,0" VerticalAlignment="Top" /> 
           <!--<Rectangle Height="100" Width="100" Fill="#FFE5001b" Margin="12,0,9,0"/>--> 
           <StackPanel Width="311"> 
            <TextBlock Text="{Binding Title}" TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}" /> 
           </StackPanel> 
          </StackPanel> 
         </DataTemplate> 
        </ListBox.ItemTemplate> 
       </ListBox>     
       <!--Double line list with image placeholder and text wrapping--> 
      </Grid> 
     </controls:PanoramaItem> 

這裏是後端代碼:

 // Load data for the ViewModel Items 
     private void MainPage_Loaded(object sender, RoutedEventArgs e) 
     { 
      if (!App.ViewModel.IsDataLoaded) 
      { 
       App.ViewModel.LoadData(); 
       progressBar.Visibility = Visibility.Collapsed; 
       headlines.Visibility = Visibility.Visible; 
      } 
     } 
+0

確保ProgressBar足夠大(以高度表示)。 – keyboardP

+0

如果我現在用這種方法來看問題。的XAML代碼如下: <工具箱:PerformanceProgressBar X:名稱= 「performanceProgressBar」 保證金= 「0,-40,0,0」 IsIndeterminate = 「真」 能見度= 「{結合ShowProgressBar}」 Grid.ColumnSpan = 「2」/> 和後面的代碼如下:! 私人布爾ShowProgressBar { 得到{App.ViewModel.IsDataLoaded; } } 數據加載後進度條並不會消失,即ShowProgressBar爲false。 –

+0

@SalmanJamal你可以編輯你的帖子。它比評論更可讀。 – McKay

回答

1

我推薦使用toolkit中的PerformanceProgressBar。

它在合成器線程上運行,所以它不會阻塞UI的東西。

+0

這仍然沒有解決問題。 –

0

在以下代碼:

if (!App.ViewModel.IsDataLoaded) 
{ 
    App.ViewModel.LoadData(); 
    progressBar.Visibility = Visibility.Collapsed; 
    headlines.Visibility = Visibility.Visible; 
} 

如果App.ViewModel.LoadData()是同步方法,吳丹可保持你的用戶界面不被更新。

嘗試將整個MainPage_Loaded代碼放入一個單獨的方法中,並將其異步調用。

0

如果我正確地閱讀了最新的評論,現在的問題是可見的值初始爲真,因爲數據正在加載,並且數據加載時再也不會再發生綁定。如果需要,我會建議連接到一個事件(並在數據模型上生成)

App.ViewModel.OnDataLoaded += (s, e) => performanceProgressBar.Visibility = Visibility.Hidden