При переключении на сводные элементы, которые загружают данные, я испытываю заикание при переключении с одного элемента на другой. Я разделил загрузку данных в отдельный поток, и это помогло, но я все еще испытываю некоторую плохую производительность .... Интересно, были ли у вас, ребята, какие-нибудь идеи ....
Вот основной пункт
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Pivot control-->
<controls:Pivot Name="panCorals" Title="Corals" Foreground="#01487e"
SelectionChanged="panCorals_SelectionChanged">
<controls:Pivot.Background>
<ImageBrush ImageSource="PivotBackground.png"/>
</controls:Pivot.Background>
<!--Search Corals-->
<controls:PivotItem Header="Search" Foreground="#01487e">
<Grid>
<toolkit:PerformanceProgressBar Name="SearchCoralsProgressBar" HorizontalAlignment="Left"
VerticalAlignment="Top" Width="466"
IsEnabled="{Binding IsSearchLoading}" IsIndeterminate="{Binding IsSearchLoading}" />
<StackPanel>
<TextBox Name="txtSearchTerm" KeyDown="txtSearchTerm_KeyDown" />
<ListBox Name="lbSearchCorals" Margin="0,0,-12,0" ItemsSource="{Binding SearchCorals}"
SelectionChanged="lbSearchCorals_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<Image Source="{Binding MainImageURI}" Height="100" Width="100" Margin="12,0,9,0" />
<StackPanel Width="311">
<TextBlock Text="{Binding CommonName}" Foreground="#112d42" TextWrapping="NoWrap" Style="{StaticResource PhoneTextTitle2Style}"/>
<TextBlock Text="{Binding ScientificName}" Foreground="#112d42" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>
</controls:PivotItem>
<!--Top Corals-->
<controls:PivotItem Header="Top" Foreground="#01487e" VerticalAlignment="Top" >
<Grid>
<toolkit:PerformanceProgressBar Name="TopCoralsProgressBar" HorizontalAlignment="Left"
VerticalAlignment="Top" Width="466"
IsEnabled="{Binding IsTopLoading}" IsIndeterminate="{Binding IsTopLoading}" />
<ListBox Name="lbTopCorals" Margin="0,0,-12,0" ItemsSource="{Binding TopCorals}" SelectionChanged="lbTopCorals_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<Image Source="{Binding MainImageURI}" Height="100" Width="100" Margin="12,0,9,0" />
<StackPanel Width="311">
<TextBlock Text="{Binding CommonName}" Foreground="#112d42" TextWrapping="NoWrap" Style="{StaticResource PhoneTextTitle2Style}"/>
<TextBlock Text="{Binding ScientificName}" Foreground="#112d42" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Margin="10,50,0,0" Orientation="Horizontal">
<TextBlock x:Name="tbProgress"/>
</StackPanel>
</Grid>
</controls:PivotItem>
<!--New Corals-->
<controls:PivotItem Header="New">
<Grid>
<toolkit:PerformanceProgressBar Name="NewCoralsProgressBar" HorizontalAlignment="Left"
VerticalAlignment="Top" Width="466"
IsEnabled="{Binding IsNewLoading}" IsIndeterminate="{Binding IsNewLoading}" />
<ListBox Name="lbNewCorals" Margin="0,0,-12,0" ItemsSource="{Binding NewCorals}" SelectionChanged="lbNewCorals_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<Image Source="{Binding MainImageURI}" Height="100" Width="100" Margin="12,0,9,0" />
<StackPanel Width="311">
<TextBlock Text="{Binding CommonName}" Foreground="#112d42" TextWrapping="NoWrap" Style="{StaticResource PhoneTextTitle2Style}"/>
<TextBlock Text="{Binding ScientificName}" Foreground="#112d42" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</controls:PivotItem>
</controls:Pivot>
</Grid>
И код позади ...
private void panCorals_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
switch (panCorals.SelectedIndex)
{
case 0: //search corals
break;
case 1: //top corals
if (!App.vmCoral.IsTopDataLoaded)
{
App.vmCoral.IsTopLoading = true;
if (App.HasConnectivity)
{
//get corals from web
bw.DoWork += new DoWorkEventHandler(bw_DoWorkTopCoralsWeb);
if (bw.IsBusy != true)
{
bw.RunWorkerAsync();
}
}
else
{
//get saved corals from device
bw.DoWork += new DoWorkEventHandler(bw_DoWorkTopCoralsSaved);
if (bw.IsBusy != true)
{
bw.RunWorkerAsync();
}
}
}
break;
case 2: //new corals
if (!App.vmCoral.IsNewDataLoaded)
{
App.vmCoral.IsNewLoading = true;
if (App.HasConnectivity)
{
//get corals from web
bw.DoWork += new DoWorkEventHandler(bw_DoWorkNewCoralsWeb);
if (bw.IsBusy != true)
{
bw.RunWorkerAsync();
}
}
else
{
//get saved corals from device
bw.DoWork += new DoWorkEventHandler(bw_DoWorkNewCoralsSaved);
if (bw.IsBusy != true)
{
bw.RunWorkerAsync();
}
}
}
break;
default:
break;
}
}