当列表框完成加载其数据时,是否有一个我可以监听的事件?我有一个文本框和一个列表框,当用户按 Enter 键时,列表框将填充来自 Web 服务的结果。我想在列表框加载时运行进度栏,并在完成后折叠它......
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>
这是我的助手转换器类......
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> { }
在我的 App.xaml 中...
xmlns:HelperClasses="clr-namespace:MyVirtualHealthCheck.HelperClasses"
...
<HelperClasses:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" TrueValue="Visible" FalseValue="Collapsed" />
视图模型....
...
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;
}