Windows Phone 7上的ProgressBar未显示

时间:2011-12-28 22:56:31

标签: windows-phone-7

我正在尝试在应用程序获取数据时在我的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;
            }
        }

3 个答案:

答案 0 :(得分:1)

我建议使用toolkit中的PerformanceProgressBar。

它在合成器线程上运行,因此它不会阻止UI事物。

答案 1 :(得分:0)

在以下代码中:

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

如果App.ViewModel.LoadData()是同步方法,那么可能会阻止您更新UI。

尝试将整个MainPage_Loaded代码放入单独的方法中并异步调用它。

答案 2 :(得分:0)

如果我正确地阅读了您最近的评论,那么您现在遇到的问题是可见的值是initialy true,因为数据正在加载,然后在加载数据时再也不会再发生绑定。我建议连接到一个事件(如果需要,可以在数据模型上进行)

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