Well, you have almost solved this, at least you have described the solution for the second point.
It's very simple, just put the TextBlock and ProgressBar under your Pivot in your xaml so that they display the ontop of the pivot element. You can then arrange them using the HorizontalAlignment, VerticalAlignment, and Margin functions. The code below should put them in the middle of your page:
<phone:PhoneApplicationPage> ... <Grid x:Name="LayoutRoot" Background="Transparent"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <phone:Pivot Title="MyTitle"> </phone:Pivot> <TextBlock Name="ProgressText" Text="Loading..." Visibility="Collapsed" VerticalAlignment="Center" HorizontalAlignment="Stretch"/> <ProgressBar Name="ProgressBar" Visibility="Collapsed" IsIndeterminate="True" VerticalAlignment="Center" HorizontalAlignment="Stretch"/> </Grid> <phone:PhoneApplicationPage>
Almost as easy. I suspect your ViewModel implements INotifyPropertyChanged or comes from some class that does this? If not, how to do it. Then add this property to your ViewModel:
private bool _IsLoading = false; public bool IsLoading { get { return _IsLoading; } set { if (_IsLoading != value) { _IsLoading = value; NotifyPropertyChanged("IsLoading"); } } }
(With NotifyPropertyChanged your version will be:
public event PropertyChangedEventHandler PropertyChanged; public void NotifyPropertyChanged(String name) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) handler(this, new PropertyChangedEventArgs(name)); }
If you don't already have a BooleanToVisibilityConverter, add this class to convert the boolean value to visible in xaml:
public class BooleanToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return (value is bool && (bool)value) ? Visibility.Visible : Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return value is Visibility && (Visibility)value == Visibility.Visible; } }
In your MainPage creation, you set the DataContext of the entire page or just the TextBlock and ProgressBar as your ViewModel (or you do it through resources and xaml, but it does not matter), add a BooleanToVisibilityConverter as a page resource similar to this:
<phone:PhoneApplicationPage.Resources> <local:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> </phone:PhoneApplicationpage.Resources>
and bind the visibility properties of TextBlock and ProgressBar to the IsLoading property of your ViewModel:
<TextBlock Name="ProgressText" Text="Loading..." Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityConverter}}" VerticalAlignment="Center" HorizontalAlignment="Stretch"/> <ProgressBar Name="ProgressBar" Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityConverter}}" IsIndeterminate="True" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
The last thing to do:
At the beginning of LoadSomething () you set IsLoading = true; and at the end of the HandleResponse method IsLoading = false; and that should do it.
source share