Windows Phone 7 progress bar for list download data

Is there an event that I can listen to when the list has finished loading data? I have a text box and a list, when the user presses Enter, the list contains data from the web service. I would like to start the progress bar when the list is loading and reset when it ends.

UPDATE

    <controls:PivotItem Header="food" Padding="0 110 0 0">

            <Grid x:Name="ContentFood" Grid.Row="2" >

                <StackPanel>
                    ...
                    ...

                    <toolkit:PerformanceProgressBar Name="ppbFoods" HorizontalAlignment="Left" 
                        VerticalAlignment="Center"
                        Width="466" IsIndeterminate="{Binding IsDataLoading}" 
                        Visibility="{Binding IsDataLoading, Converter={StaticResource BoolToVisibilityConverter}}"
                        />


                    <!--Food Results-->
                    <ListBox x:Name="lbFoods" ItemsSource="{Binding Foods}" Padding="5" 
                             SelectionChanged="lbFoods_SelectionChanged" Height="480" >
                        ....
                    </ListBox>

                </StackPanel>
            </Grid>


        </controls:PivotItem>

Here is my helper converter class ....

    public class BoolToValueConverter<T> : IValueConverter
{
    public T FalseValue { get; set; }
    public T TrueValue { get; set; }

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value == null)
            return FalseValue;
        else
            return (bool)value ? TrueValue : FalseValue;
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return value != null ? value.Equals(TrueValue) : false;
    }
}

public class BoolToStringConverter : BoolToValueConverter<String> { }
public class BoolToBrushConverter : BoolToValueConverter<Brush> { }
public class BoolToVisibilityConverter : BoolToValueConverter<Visibility> { }
public class BoolToObjectConverter : BoolToValueConverter<Object> { }

In my App.xaml ....

    xmlns:HelperClasses="clr-namespace:MyVirtualHealthCheck.HelperClasses"
    ...
    <HelperClasses:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" TrueValue="Visible" FalseValue="Collapsed" />

ViewModel ....

    ...
    public bool IsDataLoading
    {
        get;
        set;
    }
    ...
    public void GetFoods(string strSearch)
    {
        IsDataLoading = true;
        WCFService.dcFoodInfoCollection localFoods = IsolatedStorageCacheManager<WCFService.dcFoodInfoCollection>.Retrieve("CurrentFoods");

            if (localFoods != null)
            {
                Foods = localFoods;
            }
            else
            {
                GetFoodsFromWCF(strSearch);
            }
    }


    public void GetFoodsFromWCF(string strSearch)
    {
        IsDataLoading = true;
        wcfProxy.GetFoodInfosAsync(strSearch);
        wcfProxy.GetFoodInfosCompleted += new EventHandler<WCFService.GetFoodInfosCompletedEventArgs>(wcfProxy_GetFoodInfosCompleted);
    }

    void wcfProxy_GetFoodInfosCompleted(object sender, WCFService.GetFoodInfosCompletedEventArgs e)
    {
        WCFService.dcFoodInfoCollection foods = e.Result;
        if (foods != null)
        {
            //set current foods to the results from the web service
            this.Foods = foods;
            this.IsDataLoaded = true;

            //save foods to phone so we can use cached results instead of round tripping to the web service again
            SaveFoods(foods);
        }
        else
        {
            Debug.WriteLine("Web service says: " + e.Result);
        }
        IsDataLoading = false;
    }
+3
source share
3 answers

. , .
.


- , . , :

:

public class MyViewModel : INotifyPropertyChanged
{
    private bool isLoading;
    public bool IsLoading
    {
        get { return isLoading; }

        set
        {
            isLoading = value;
            NotifyPropertyChanged("IsLoading");
        }
    }

    public void SimulateLoading()
    {
        var bw = new BackgroundWorker();

        bw.RunWorkerCompleted += (s, e) => 
            Deployment.Current.Dispatcher.BeginInvoke(
                () => { IsLoading = false; });

        bw.DoWork += (s, e) =>
        {
            Deployment.Current.Dispatcher.BeginInvoke(() => { IsLoading = true; });
            Thread.Sleep(5000);
        };

        bw.RunWorkerAsync();
    }

    public event PropertyChangedEventHandler PropertyChanged;

    private void NotifyPropertyChanged(String propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

XAML:

<toolkit:PerformanceProgressBar IsEnabled="{Binding IsLoading}" 
                                IsIndeterminate="{Binding IsLoading}"/>

DataContext , SimulateLoading() .

:
IsIndeterminate - bool, .

+3

, .

"" .

Private Sub tProgress_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tProgress.Tick
        Count = (Count + 1) Mod ProgressBar1.Maximum
        ProgressBar1.Value = Count
    End Sub

Public Sub KillMe(ByVal o As Object, ByVal e As EventArgs)

        Me.Close()

    End Sub

Dim ProgressThread As New Threading.Thread(New Threading.ThreadStart(AddressOf StartProgress))
ProgressThread.Start()

Public Sub ProgressSplash()
        'Show please wait splash
        Progress = New frmProgress
        Application.Run(Progress)

End Sub

,

Public Sub CloseProgress()

        If Progress IsNot Nothing Then

            Progress.Invoke(New EventHandler(AddressOf Progress.KillMe))
            Progress.Dispose()
            Progress = Nothing
        End If

    End Sub

"" , .

, VB.NET

+2

, Windows Phone 7 Windows Phone 7

canvas control 360 .

You simply call storyboard.Begin()when you want to display the progress bar and set the canvas visibility to visible and when your data is listBoxfully loaded, set the canvas visibility to Collapsed and callstoryboard.Stop();

+1
source

All Articles