Skip to content

Commit 0d58757

Browse files
committed
finsih 加载中提示 and 瀑布流加载
1 parent 696021a commit 0d58757

8 files changed

Lines changed: 132 additions & 43 deletions

File tree

MoePicture/CC/PictureWall.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private static void RequestArrange(DependencyObject d, DependencyPropertyChanged
6969
/// </summary>
7070
protected override Size MeasureOverride(Size availableSize)
7171
{
72-
var measure = base.MeasureOverride(availableSize);
72+
//var measure = base.MeasureOverride(availableSize);
7373

7474
double itemFixed = 0;
7575
Size requestSize = Size.Empty;

MoePicture/Styles/ProgressRing.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:local="using:MoePicture.Styles">
55
<Style x:Key="MyProgressRingStyle" TargetType="ProgressRing">
6-
<Setter Property="Width" Value="60" />
7-
<Setter Property="Height" Value="60" />
6+
<!--<Setter Property="Width" Value="60" />
7+
<Setter Property="Height" Value="60" />-->
88
<Setter Property="Background" Value="Transparent" />
99
<Setter Property="Foreground" Value="White" />
1010
<Setter Property="IsHitTestVisible" Value="False" />

MoePicture/UC/ButtonBar.xaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
mc:Ignorable="d">
1010
<UserControl.Resources>
1111
<Converters:TagStringConverter x:Key="TagStringConverter" />
12+
<Converters:BoolVisibilityConverter x:Key="BoolVisibilityConverter" />
1213
</UserControl.Resources>
1314
<Grid>
1415
<Grid
@@ -24,6 +25,36 @@
2425
Foreground="White"
2526
Text="{Binding Tag, Converter={StaticResource TagStringConverter}}" />
2627
</Grid>
28+
<Grid
29+
Height="44"
30+
Margin="0,88,0,0"
31+
HorizontalAlignment="Right"
32+
VerticalAlignment="Top"
33+
DataContext="{Binding PicturesVM, Source={StaticResource Locator}}"
34+
Visibility="{Binding PictureItems.Busy, Mode=OneWay, Converter={StaticResource BoolVisibilityConverter}}">
35+
<Grid.ColumnDefinitions>
36+
<ColumnDefinition Width="auto" />
37+
<ColumnDefinition Width="auto" />
38+
</Grid.ColumnDefinitions>
39+
<Canvas
40+
Grid.ColumnSpan="2"
41+
Background="{StaticResource Black50AcrylicBrush}"
42+
Opacity="0.9" />
43+
<ProgressRing
44+
Width="40"
45+
Height="40"
46+
Padding="8"
47+
HorizontalAlignment="Left"
48+
IsActive="{Binding PictureItems.Busy, Mode=OneWay}"
49+
Style="{StaticResource MyProgressRingStyle}" />
50+
<TextBlock
51+
Grid.Column="2"
52+
Margin="8,0,8,0"
53+
VerticalAlignment="Center"
54+
FontSize="32"
55+
Foreground="White"
56+
Text="加载中..." />
57+
</Grid>
2758
<Grid
2859
Margin="0,0,20,48"
2960
HorizontalAlignment="Right"

MoePicture/UC/PictureGrid.xaml

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,56 @@
1414
<Converters:IntBoolConverter x:Key="IntBoolConverter" />
1515
</UserControl.Resources>
1616
<Grid DataContext="{Binding PicturesVM, Source={StaticResource Locator}}">
17-
<ProgressRing IsActive="{Binding PictureItems.Count, Converter={StaticResource IntBoolConverter}, Mode=OneWay}" Style="{StaticResource MyProgressRingStyle}" />
18-
<ListView
19-
x:Name="listView"
20-
IsItemClickEnabled="True"
21-
ItemClick="GridView_ItemClick"
22-
ItemsSource="{Binding PictureItems}">
23-
<ListView.ItemContainerStyle>
24-
<Style TargetType="ListViewItem">
25-
<Setter Property="Padding" Value="0" />
26-
<Setter Property="Margin" Value="0" />
27-
<Setter Property="BorderThickness" Value="0" />
28-
</Style>
29-
</ListView.ItemContainerStyle>
30-
<ListView.ItemsPanel>
31-
<ItemsPanelTemplate>
32-
<CC:PictureWall />
33-
</ItemsPanelTemplate>
34-
</ListView.ItemsPanel>
35-
<ListView.ItemTemplate>
36-
<DataTemplate x:DataType="Models:PictureItem">
37-
<Grid Loaded="RootGrid_Loaded" SizeChanged="RootGrid_SizeChanged">
38-
<Image Source="{Binding ImageSource}" Stretch="UniformToFill" />
39-
<Border x:Name="MaskBorder" Background="#50000000">
40-
<StackPanel>
41-
<TextBlock
42-
Margin="12"
43-
Foreground="White"
44-
Text="{Binding Title}"
45-
TextWrapping="Wrap" />
46-
</StackPanel>
47-
</Border>
48-
</Grid>
49-
</DataTemplate>
50-
</ListView.ItemTemplate>
51-
</ListView>
17+
18+
<ScrollViewer x:Name="scrollView" ViewChanged="scrollView_ViewChanged">
19+
<ListView
20+
x:Name="listView"
21+
IsItemClickEnabled="True"
22+
ItemClick="GridView_ItemClick"
23+
ItemsSource="{Binding PictureItems}">
24+
<ListView.ItemContainerStyle>
25+
<Style TargetType="ListViewItem">
26+
<Setter Property="Padding" Value="0" />
27+
<Setter Property="Margin" Value="0" />
28+
<Setter Property="BorderThickness" Value="0" />
29+
</Style>
30+
</ListView.ItemContainerStyle>
31+
<ListView.ItemsPanel>
32+
<ItemsPanelTemplate>
33+
<CC:PictureWall />
34+
</ItemsPanelTemplate>
35+
</ListView.ItemsPanel>
36+
<ListView.ItemTemplate>
37+
<DataTemplate x:DataType="Models:PictureItem">
38+
<Grid Loaded="RootGrid_Loaded" SizeChanged="RootGrid_SizeChanged">
39+
<Image Source="{Binding ImageSource}" Stretch="UniformToFill" />
40+
<Border x:Name="MaskBorder" Background="#50000000">
41+
<StackPanel>
42+
<TextBlock
43+
Margin="12"
44+
Foreground="White"
45+
Text="{Binding Title}"
46+
TextWrapping="Wrap" />
47+
</StackPanel>
48+
</Border>
49+
</Grid>
50+
</DataTemplate>
51+
</ListView.ItemTemplate>
52+
</ListView>
53+
</ScrollViewer>
54+
<!--<StackPanel
55+
HorizontalAlignment="Center"
56+
VerticalAlignment="Bottom"
57+
Background="Gray"
58+
Orientation="Horizontal">
59+
<Button x:Name="Add_Button" Margin="4">
60+
add
61+
</Button>
62+
<Button x:Name="Insert_Button" Margin="4">insert</Button>
63+
<Button x:Name="Remove_Button" Margin="4">remove</Button>
64+
<Button x:Name="Reset_Button" Margin="4">
65+
initial
66+
</Button>
67+
</StackPanel>-->
5268
</Grid>
5369
</UserControl>

MoePicture/UC/PictureGrid.xaml.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using CommonServiceLocator;
2+
using GalaSoft.MvvmLight.Threading;
23
using MoePicture.CC;
34
using MoePicture.ViewModels;
45
using System;
@@ -33,9 +34,18 @@ public sealed partial class PictureGrid : UserControl
3334
public PictureGrid()
3435
{
3536
this.InitializeComponent();
37+
ServiceLocator.Current.GetInstance<PictureItemsVM>().ScrollRefreshEvent += Refresh;
3638
this.compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
3739
}
3840

41+
private void Refresh()
42+
{
43+
DispatcherHelper.CheckBeginInvokeOnUI(() =>
44+
{
45+
scrollView.ChangeView(null, 0, null, true);
46+
});
47+
}
48+
3949
private void RootGrid_Loaded(object sender, RoutedEventArgs e)
4050
{
4151
var rootGrid = sender as Grid;
@@ -140,5 +150,23 @@ private void LoadMore()
140150
ServiceLocator.Current.GetInstance<PictureItemsVM>().PictureItems.LoadMoreItemsAsync(100);
141151
}
142152
}
153+
154+
private void scrollView_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
155+
{
156+
var verticalOffset = scrollView.VerticalOffset;
157+
var maxVerticalOffset = scrollView.ScrollableHeight; //sv.ExtentHeight - sv.ViewportHeight;
158+
159+
if (maxVerticalOffset < 0 ||
160+
verticalOffset == maxVerticalOffset)
161+
{
162+
// Scrolled to bottom
163+
LoadMore();
164+
}
165+
//else
166+
//{
167+
// // Not scrolled to bottom
168+
// rect.Fill = new SolidColorBrush(Colors.Yellow);
169+
//}
170+
}
143171
}
144172
}

MoePicture/ViewModels/PictureItems/IncrementalLoadingBase.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,15 @@ public bool HasMoreItems
112112
get { return HasMoreItemsOverride(); }
113113
}
114114

115+
115116
public Windows.Foundation.IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
116117
{
117-
if (_busy)
118+
if (Busy)
118119
{
119120
throw new InvalidOperationException("Only one operation in flight at a time");
120121
}
121122

122-
_busy = true;
123+
Busy = true;
123124

124125
return AsyncInfo.Run((c) => LoadMoreItemsAsync(c, count));
125126
}
@@ -168,7 +169,7 @@ private async Task<LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c,
168169
//}
169170
finally
170171
{
171-
_busy = false;
172+
Busy = false;
172173
}
173174
}
174175

@@ -206,7 +207,9 @@ private void NotifyOfInsertedItems(int baseIndex, int count)
206207
protected List<T> _storage = new List<T>();
207208

208209
// 表示后台线程是否正在进行,一次只能进行一个线程
209-
protected bool _busy = false;
210+
private bool busy = false;
211+
protected bool Busy { get => busy; set { busy = value; OnPropertyChanged("Busy"); } }
212+
210213

211214
#endregion State
212215
}

MoePicture/ViewModels/PictureItems/PictureItems.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ public class PictureItems : IncrementalLoadingBase<PictureItem>
2323
/// <summary> 数据库实例 </summary>
2424
public DataBase DB;
2525

26-
public bool Busy { get { return _busy; } }
26+
public bool Busy
27+
{
28+
get { return base.Busy; }
29+
set
30+
{
31+
base.Busy = value;
32+
}
33+
}
2734

2835
#endregion Propeities
2936

MoePicture/ViewModels/PictureItemsVM.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class PictureItemsVM : ViewModelBase
3131
/// <summary> 切换网站 </summary>
3232
private RelayCommand<string> changeWebsiteCommand;
3333

34+
public delegate void ScrollRefresh();
35+
public ScrollRefresh ScrollRefreshEvent;
36+
3437
/// <summary> TilesUpdater实例 </summary>
3538
private static TilesUpdater Tiles = new TilesUpdater();
3639

@@ -91,6 +94,7 @@ private void ChangeWebsite(string websiteStr)
9194
private void RefreshPictures()
9295
{
9396
PictureItems = new PictureItems(Type, Tag);
97+
ScrollRefreshEvent?.Invoke();
9498
ServiceLocator.Current.GetInstance<ShellVM>().ShowError = false;
9599
}
96100
/// <summary> 点击单个对象 </summary>

0 commit comments

Comments
 (0)