XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFENewsApplication

【WinUI】新闻软件

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFENewsApplication

完成轮播图

3435aaa
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

7 个文件 +226 -64
Added XFENewsApplication/Models/FlipImage.cs +9 -0
@@ -0,0 +1,9 @@
1 namespace XFENewsApplication.Models;
2
3 public class FlipImage
4 {
5 public string ImageUrl { get; set; } = string.Empty;
6 public string Description { get; set; } = string.Empty;
7 public string Attribution { get; set; } = string.Empty;
8 public string Title { get; set; } = string.Empty;
9 }
Added XFENewsApplication/Models/FlipImageArticlePart.cs +6 -0
@@ -0,0 +1,6 @@
1 namespace XFENewsApplication.Models;
2
3 public class FlipImageArticlePart : ArticlePart
4 {
5 public List<FlipImage> Images { get; set; } = [];
6 }
Modified XFENewsApplication/Utilities/Helper/ArticleDisplayHelper.cs +24 -8
@@ -33,6 +33,25 @@ public static class ArticleDisplayHelper
33 33 AuthorName = document.RootElement.TryGetProperty("authors", out var authors) && authors.EnumerateArray().Any() ? string.Join(", ", authors.EnumerateArray().Select(x => x.GetProperty("name").ToString())) : providerName
34 34 });
35 35 }
36 if (document.RootElement.TryGetProperty("slides", out var slides) && slides.EnumerateArray().Any())
37 {
38 var flipImages = new List<FlipImage>();
39 foreach (var slide in slides.EnumerateArray())
40 {
41 var imageProperty = slide.GetProperty("image");
42 flipImages.Add(new()
43 {
44 ImageUrl = imageProperty.GetProperty("url").ToString(),
45 Description = imageProperty.TryGetProperty("caption", out var description) ? description.ToString() : string.Empty,
46 Attribution = imageProperty.TryGetProperty("attribution", out var attribution) ? attribution.ToString() : string.Empty,
47 Title = slide.TryGetProperty("title", out var titleProperty) ? titleProperty.ToString() : string.Empty
48 });
49 }
50 articleParts.Add(new FlipImageArticlePart
51 {
52 Images = flipImages
53 });
54 }
36 55 foreach (var imageNode in document.RootElement.GetProperty("imageResources").EnumerateArray())
37 56 imageDictionary.Add(imageNode.GetProperty("cmsId").ToString(), imageNode.GetProperty("url").ToString());
38 57 var htmlDocument = new HtmlDocument();
@@ -90,15 +109,12 @@ public static class ArticleDisplayHelper
90 109 });
91 110 break;
92 111 case "strong":
93 if (parentNode.ParentNode.Name == "p")
112 var bold = new Bold();
113 bold.Inlines.Add(new Run
94 114 {
95 var bold = new Bold();
96 bold.Inlines.Add(new Run
97 {
98 Text = node.InnerText
99 });
100 CheckLastArticlePart(articleParts, parentNode.ParentNode, bold);
101 }
115 Text = node.InnerText
116 });
117 CheckLastArticlePart(articleParts, parentNode.ParentNode, bold);
102 118 break;
103 119 case "blockquote":
104 120 if (node.InnerText.IsNullOrWhiteSpace())
Modified XFENewsApplication/Utilities/Selector/ArticleDataTemplateSelector.cs +3 -0
@@ -12,6 +12,7 @@ public partial class ArticleDataTemplateSelector : DataTemplateSelector
12 12 public DataTemplate? QuoteDataTemplate { get; set; }
13 13 public DataTemplate? CustomTextDataTemplate { get; set; }
14 14 public DataTemplate? ImageDataTemplate { get; set; }
15 public DataTemplate? FlipImageDataTemplate { get; set; }
15 16 protected override DataTemplate? SelectTemplateCore(object item)
16 17 {
17 18 if (item is ArticlePart articlePart)
@@ -30,6 +31,8 @@ public partial class ArticleDataTemplateSelector : DataTemplateSelector
30 31 return ImageDataTemplate;
31 32 if (articlePart is AuthorArticlePart)
32 33 return AuthorDataTemplate;
34 if (articlePart is FlipImageArticlePart)
35 return FlipImageDataTemplate;
33 36 return TextDataTemplate;
34 37 }
35 38 return DefaultDataTemplate;
Modified XFENewsApplication/ViewModels/NewsViewPageViewModel.cs +119 -47
@@ -1,9 +1,12 @@
1 1 using CommunityToolkit.Mvvm.ComponentModel;
2 2 using CommunityToolkit.Mvvm.Input;
3 using Microsoft.UI.Text;
4 using Microsoft.UI.Xaml.Media;
5 using Microsoft.UI.Xaml.Media.Imaging;
3 6 using System.Collections.ObjectModel;
4 7 using System.Diagnostics;
5 using System.Threading.Tasks;
6 8 using Windows.ApplicationModel.DataTransfer;
9 using XFEExtension.NetCore.StringExtension;
7 10 using XFEExtension.NetCore.WinUIHelper.Interface.Services;
8 11 using XFEExtension.NetCore.WinUIHelper.Utilities;
9 12 using XFENewsApplication.Core.Models;
@@ -29,13 +32,20 @@ public partial class NewsViewPageViewModel : ViewModelBase
29 32 bool isContentLoadingVisible = true;
30 33 [ObservableProperty]
31 34 bool isSideBarMoreContentLoadingVisible = false;
35 [ObservableProperty]
36 string searchText = string.Empty;
37 [ObservableProperty]
38 string previewImageUrl = string.Empty;
32 39 private List<NewsSource> newsList = [];
40 private List<NewsSource> lastNewsList = [];
33 41 private string? currentNewsId;
34 42 private string? currentNewsContent;
43 private string? lastNewsSource;
35 44 private bool isLoadingNews = false;
36 45 private int skip = 0;
37 46 private int servedCardCount = 0;
38 47 private int lastCardCount = 0;
48 private int lastSelectedNews = 0;
39 49 public INavigationParameterService<string> NavigationParameterService { get; set; } = ServiceManager.GetService<INavigationParameterService<string>>();
40 50 public IListViewService NewsListViewService { get; set; } = ServiceManager.GetService<IListViewService>();
41 51 public IListViewService ContentListViewService { get; set; } = ServiceManager.GetService<IListViewService>();
@@ -53,30 +63,6 @@ public partial class NewsViewPageViewModel : ViewModelBase
53 63 NewsListViewService.SelectionChanged += ListViewService_SelectionChanged;
54 64 }
55 65
56 private void ListView_Loaded(object sender, RoutedEventArgs e)
57 {
58 NewsListViewService.ListViewScrollViewer!.ViewChanged += ListViewScrollViewer_ViewChanged;
59 }
60
61 private async void ListViewScrollViewer_ViewChanged(object? sender, ScrollViewerViewChangedEventArgs e)
62 {
63 if (sender is ScrollViewer scrollViewer)
64 {
65 switch (NavigationParameterService.Parameter)
66 {
67 case "MSN":
68 if (!isLoadingNews || TokenSource is null || TokenSource.IsCancellationRequested)
69 if (scrollViewer.ScrollableHeight - scrollViewer.VerticalOffset < 300)
70 await GetNews();
71 break;
72 default:
73 break;
74 }
75 }
76 }
77
78 partial void OnSideBarWidthChanged(double value) => SystemProfile.SideBarWidth = value;
79
80 66 private async void NavigationParameterService_ParameterChange(object? sender, string? e)
81 67 {
82 68 NewsListViewService.ListView.Loaded += ListView_Loaded;
@@ -91,25 +77,53 @@ public partial class NewsViewPageViewModel : ViewModelBase
91 77 IsContentLoadingVisible = true;
92 78 NewsList.Clear();
93 79 ContentList.Clear();
80 SearchText = string.Empty;
94 81 currentNewsId = string.Empty;
82 newsList.Clear();
95 83 }
96 84 switch (e)
97 85 {
98 86 case "MSN":
99 87 if (NavigationViewService is not null)
100 88 {
101 NavigationViewService.ContentMargin = new(0);
102 NavigationViewService.Header = null;
89 NavigationViewService.ContentMargin = new(0, 24, 0, 0);
90 var stackPanel = new StackPanel
91 {
92 Orientation = Orientation.Horizontal,
93 Spacing = 24
94 };
95 stackPanel.Children.Add(new Image
96 {
97 Source = new BitmapImage(new("https://www.msn.com/favicon.ico"))
98 });
99 stackPanel.Children.Add(new TextBlock
100 {
101 Text = "MSN新闻",
102 FontSize = 28,
103 FontWeight = FontWeights.SemiBold
104 });
105 NavigationViewService.Header = stackPanel;
106 }
107 if (lastNewsList.Count > 0 && lastNewsSource == "MSN")
108 {
109 newsList = lastNewsList;
110 LoadNewsSource(newsList);
111 NewsListViewService.ListView.ScrollIntoView(NewsList[lastSelectedNews], ScrollIntoViewAlignment.Leading);
103 112 }
104 await GetNews();
105 SelectedIndex = 0;
113 else
114 {
115 await GetNews();
116 }
117 SelectedIndex = lastSelectedNews;
106 118 IsSideBarMoreContentLoadingVisible = true;
119 lastNewsSource = "MSN";
107 120 break;
108 121 case "Favorite":
109 122 IsSideBarMoreContentLoadingVisible = false;
110 123 if (NavigationViewService is not null)
111 124 NavigationViewService.ContentMargin = new(0, 24, 0, 0);
112 LoadNewsSource(UserProfile.FavoriteArticleList.Select(favorite => favorite.NewsSource));
125 newsList = [.. UserProfile.FavoriteArticleList.Select(favorite => favorite.NewsSource)];
126 LoadNewsSource(newsList);
113 127 if (UserProfile.FavoriteArticleList.Count > 0)
114 128 SelectedIndex = 0;
115 129 IsContentLoadingVisible = false;
@@ -118,7 +132,8 @@ public partial class NewsViewPageViewModel : ViewModelBase
118 132 IsSideBarMoreContentLoadingVisible = false;
119 133 if (NavigationViewService is not null)
120 134 NavigationViewService.ContentMargin = new(0, 24, 0, 0);
121 LoadNewsSource(UserProfile.HistoryArticleList);
135 newsList = [.. UserProfile.HistoryArticleList];
136 LoadNewsSource(newsList);
122 137 if (UserProfile.FavoriteArticleList.Count > 0)
123 138 SelectedIndex = 0;
124 139 IsContentLoadingVisible = false;
@@ -129,9 +144,30 @@ public partial class NewsViewPageViewModel : ViewModelBase
129 144 IsSideBarLoadingVisible = false;
130 145 }
131 146
147 private void ListView_Loaded(object sender, RoutedEventArgs e)
148 {
149 NewsListViewService.ListViewScrollViewer!.ViewChanged += ListViewScrollViewer_ViewChanged;
150 }
151
152 private async void ListViewScrollViewer_ViewChanged(object? sender, ScrollViewerViewChangedEventArgs e)
153 {
154 if (sender is ScrollViewer scrollViewer)
155 {
156 switch (NavigationParameterService.Parameter)
157 {
158 case "MSN":
159 if ((!isLoadingNews || TokenSource is null || TokenSource.IsCancellationRequested) && SearchText.IsNullOrEmpty())
160 if (scrollViewer.ScrollableHeight - scrollViewer.VerticalOffset < 300)
161 await GetNews();
162 break;
163 default:
164 break;
165 }
166 }
167 }
168
132 169 private async void ListViewService_SelectionChanged(object sender, SelectionChangedEventArgs e)
133 170 {
134 ContentList.Clear();
135 171 IsFavoriteArticle = NewsListViewService.ListView.SelectedItem is NewsSource source && UserProfile.FavoriteArticleList.Any(favorite => favorite.NewsSource.Url == source.Url);
136 172 switch (NavigationParameterService.Parameter)
137 173 {
@@ -144,10 +180,31 @@ public partial class NewsViewPageViewModel : ViewModelBase
144 180 }
145 181 }
146 182
183 partial void OnSideBarWidthChanged(double value) => SystemProfile.SideBarWidth = value;
184
185 partial void OnSearchTextChanged(string value) => SearchNews(value);
186
187 private void SearchNews(string searchText)
188 {
189 if (string.IsNullOrEmpty(searchText))
190 {
191 IsSideBarMoreContentLoadingVisible = true;
192 NewsList.Clear();
193 LoadNewsSource(newsList);
194 }
195 else
196 {
197 IsSideBarMoreContentLoadingVisible = false;
198 NewsList.Clear();
199 LoadNewsSource(newsList.Where(news => news.Title.Contains(searchText, StringComparison.OrdinalIgnoreCase) || news.Abstract is not null && news.Abstract.Contains(searchText, StringComparison.OrdinalIgnoreCase)));
200 }
201 }
202
147 203 private void FavoriteChanged()
148 204 {
149 if (NewsListViewService.ListView.SelectedItem is NewsSource newsSource && UserProfile.FavoriteArticleList.FirstOrDefault(favorite => favorite.NewsSource.Url == newsSource.Url) is Article article)
205 if (NewsListViewService.ListView.SelectedItem is NewsSource newsSource && UserProfile.FavoriteArticleList.FirstOrDefault(favorite => favorite.NewsSource.Url == newsSource.Url) is Article article && SelectedIndex != -1)
150 206 {
207 ContentList.Clear();
151 208 currentNewsId = newsSource.ID;
152 209 LoadContentList(ArticleDisplayHelper.ConvertToArticlePart(article.ArticleContent));
153 210 }
@@ -155,13 +212,14 @@ public partial class NewsViewPageViewModel : ViewModelBase
155 212
156 213 private async Task NewsChanged()
157 214 {
158 IsContentLoadingVisible = true;
159 215 using var client = new HttpClient();
160 216 client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0");
161 217 int reTryTimes = 0;
162 218 Exception? exception = null;
163 if (NewsListViewService.ListView.SelectedItem is NewsSource newsSource)
219 if (NewsListViewService.ListView.SelectedItem is NewsSource newsSource && SelectedIndex != -1)
164 220 {
221 IsContentLoadingVisible = true;
222 ContentList.Clear();
165 223 currentNewsId = newsSource.ID;
166 224 while (reTryTimes < 5)
167 225 {
@@ -170,6 +228,8 @@ public partial class NewsViewPageViewModel : ViewModelBase
170 228 switch (newsSource.Source)
171 229 {
172 230 case "MSN":
231 if (NavigationParameterService.Parameter == "MSN")
232 lastSelectedNews = SelectedIndex;
173 233 var result = await client.GetStringAsync($"https://assets.msn.cn/content/view/v2/Detail/zh-cn/{newsSource.ID}");
174 234 currentNewsContent = result;
175 235 if (!CheckCurrentNewsSource(newsSource.ID))
@@ -214,22 +274,34 @@ public partial class NewsViewPageViewModel : ViewModelBase
214 274 async Task GetNews()
215 275 {
216 276 isLoadingNews = true;
277 int totalCount = 0;
217 278 var tokenSource = new CancellationTokenSource();
218 279 TokenSource = tokenSource;
219 var result = await ClimbHelper.ClimbMSNNews(tokenSource.Token, skip, lastCardCount, servedCardCount);
220 if (result.Success)
280 while (!tokenSource.IsCancellationRequested)
221 281 {
222 newsList.AddRange(result.NewsSourceList);
223 skip++;
224 servedCardCount = result.Count;
225 lastCardCount += result.Count;
226 }
227 else
228 {
229 MessageService?.ShowMessage(result.Message ?? "未知原因", "无法获取新闻", InfoBarSeverity.Warning);
282 var result = await ClimbHelper.ClimbMSNNews(tokenSource.Token, skip, lastCardCount, servedCardCount);
283 var finalResult = result.NewsSourceList.Where(newsSource => !newsList.Any(news => news.Url == newsSource.Url)).ToList();
284 if (result.Success)
285 {
286 if (finalResult.Count > 0)
287 {
288 totalCount += finalResult.Count;
289 newsList.AddRange(finalResult);
290 lastNewsList.AddRange(finalResult);
291 skip++;
292 servedCardCount = result.Count;
293 lastCardCount += result.Count;
294 if (!tokenSource.IsCancellationRequested)
295 LoadNewsSource(finalResult);
296 if (totalCount >= 10)
297 break;
298 }
299 }
300 else
301 {
302 MessageService?.ShowMessage(result.Message ?? "未知原因", "无法获取新闻", InfoBarSeverity.Warning);
303 }
230 304 }
231 if (!tokenSource.IsCancellationRequested)
232 LoadNewsSource(result.NewsSourceList);
233 305 isLoadingNews = false;
234 306 }
235 307
Modified XFENewsApplication/Views/NewsViewPage.xaml +42 -9
@@ -53,6 +53,33 @@
53 53 <DataTemplate x:Key="CustomTextDataTemplate" x:DataType="model:CustomTextArticlePart">
54 54 <ContentPresenter Content="{x:Bind CustomTextBlock}"/>
55 55 </DataTemplate>
56 <DataTemplate x:Key="FlipImageDataTemplate" x:DataType="model:FlipImageArticlePart">
57 <Grid HorizontalAlignment="Center" Margin="0,10">
58 <Border Margin="1" CornerRadius="8" Background="{ThemeResource FocusStrokeColorOuterBrush}"/>
59 <Image MaxWidth="950" MaxHeight="500" Margin="10" Source="{Binding ElementName=imageFlipView, Path=SelectedItem, Converter={StaticResource URLImageConverter}}"/>
60 <Border MaxWidth="950" MaxHeight="500" CornerRadius="8" Background="{ThemeResource AcrylicInAppFillColorDefaultBrush}">
61 <FlipView x:Name="imageFlipView" ItemsSource="{x:Bind Images}" IsTapEnabled="True" Tapped="imageFlipView_Tapped">
62 <FlipView.ItemTemplate>
63 <DataTemplate x:DataType="model:FlipImage">
64 <Grid>
65 <Image Source="{x:Bind ImageUrl, Converter={StaticResource URLImageConverter}}"/>
66 <Border x:Name="infomationBorder" Background="{ThemeResource AcrylicInAppFillColorDefaultBrush}" PointerEntered="Border_PointerEntered" PointerExited="Border_PointerExited" VerticalAlignment="Bottom" Padding="10">
67 <Border.OpacityTransition>
68 <ScalarTransition/>
69 </Border.OpacityTransition>
70 <StackPanel Orientation="Vertical">
71 <TextBlock Margin="0,10" Text="{x:Bind Title}" Visibility="{x:Bind Title, Converter={StaticResource StringEmptyVisibilityConverter}}" FontSize="18" FontWeight="SemiBold" TextWrapping="Wrap"/>
72 <TextBlock Margin="0,5" Text="{x:Bind Attribution}" Visibility="{x:Bind Attribution, Converter={StaticResource StringEmptyVisibilityConverter}}" FontSize="12" Foreground="{ThemeResource TextFillColorSecondary}" TextWrapping="Wrap"/>
73 <TextBlock Text="{x:Bind Description}" Visibility="{x:Bind Description, Converter={StaticResource StringEmptyVisibilityConverter}}" FontSize="15" TextWrapping="Wrap"/>
74 </StackPanel>
75 </Border>
76 </Grid>
77 </DataTemplate>
78 </FlipView.ItemTemplate>
79 </FlipView>
80 </Border>
81 </Grid>
82 </DataTemplate>
56 83 <DataTemplate x:Key="ImageDataTemplate" x:DataType="model:ImageArticlePart">
57 84 <Grid HorizontalAlignment="Center" Margin="0,10">
58 85 <Border Margin="1" CornerRadius="8" Background="{ThemeResource FocusStrokeColorOuterBrush}"/>
@@ -68,7 +95,7 @@
68 95 </Border>
69 96 </Grid>
70 97 </DataTemplate>
71 <selector:ArticleDataTemplateSelector x:Key="ArticleDataTemplateSelector" DefaultDataTemplate="{StaticResource TextDataTemplate}" TextDataTemplate="{StaticResource TextDataTemplate}" ImageDataTemplate="{StaticResource ImageDataTemplate}" TitleDataTemplate="{StaticResource TitleDataTemplate}" QuoteDataTemplate="{StaticResource QuoteDataTemplate}" CustomTextDataTemplate="{StaticResource CustomTextDataTemplate}" AuthorDataTemplate="{StaticResource AuthorDataTemplate}"/>
98 <selector:ArticleDataTemplateSelector x:Key="ArticleDataTemplateSelector" DefaultDataTemplate="{StaticResource TextDataTemplate}" TextDataTemplate="{StaticResource TextDataTemplate}" ImageDataTemplate="{StaticResource ImageDataTemplate}" TitleDataTemplate="{StaticResource TitleDataTemplate}" QuoteDataTemplate="{StaticResource QuoteDataTemplate}" CustomTextDataTemplate="{StaticResource CustomTextDataTemplate}" AuthorDataTemplate="{StaticResource AuthorDataTemplate}" FlipImageDataTemplate="{StaticResource FlipImageDataTemplate}"/>
72 99 </Page.Resources>
73 100
74 101 <Grid>
@@ -77,9 +104,17 @@
77 104 <ColumnDefinition Width="Auto"/>
78 105 <ColumnDefinition/>
79 106 </Grid.ColumnDefinitions>
107 <ContentDialog x:Name="previewImageContentDialog" PrimaryButtonText="保存" SecondaryButtonText="取消">
108 <Image Source="{x:Bind ViewModel.PreviewImageUrl, Mode=OneWay, Converter={StaticResource URLImageConverter}}"/>
109 </ContentDialog>
80 110 <Border x:Name="sideBar" MinWidth="300" MaxWidth="800" Width="{x:Bind ViewModel.SideBarWidth, Mode=TwoWay}">
81 111 <Grid>
82 <ListView x:Name="newsSourceListView" ItemsSource="{x:Bind ViewModel.NewsList}" SelectionMode="Single" SelectedIndex="{x:Bind ViewModel.SelectedIndex, Mode=TwoWay}" Margin="0,5,0,0">
112 <Grid.RowDefinitions>
113 <RowDefinition Height="Auto"/>
114 <RowDefinition/>
115 </Grid.RowDefinitions>
116 <AutoSuggestBox Margin="8,0,10,10" HorizontalAlignment="Stretch" PlaceholderText="搜索新闻" QueryIcon="Find" Text="{x:Bind ViewModel.SearchText, Mode=TwoWay}"/>
117 <ListView Grid.Row="1" x:Name="newsSourceListView" ItemsSource="{x:Bind ViewModel.NewsList}" SelectionMode="Single" SelectedIndex="{x:Bind ViewModel.SelectedIndex, Mode=TwoWay}" Margin="0,5,0,0">
83 118 <ListView.ItemTemplate>
84 119 <DataTemplate x:DataType="coremodel:NewsSource">
85 120 <StackPanel Orientation="Vertical" Padding="5,24" Spacing="12">
@@ -96,16 +131,14 @@
96 131 </ListView.ItemContainerStyle>
97 132 <ListView.Footer>
98 133 <Grid VerticalAlignment="Center" HorizontalAlignment="Stretch">
99 <Border Visibility="{x:Bind ViewModel.IsSideBarMoreContentLoadingVisible, Mode=OneWay}" Margin="4,0,5,10" CornerRadius="0,0,10,10" Background="{ThemeResource AccentFillColorDefaultBrush}">
100 <StackPanel Margin="0,10,0,10" HorizontalAlignment="Center" Orientation="Horizontal" Spacing="10">
101 <ProgressRing Width="30" Height="30" IsIndeterminate="True" Foreground="{ThemeResource TextOnAccentFillColorPrimaryBrush}"/>
102 <TextBlock Text="更多精彩内容加载中" FontSize="18" Foreground="{ThemeResource TextOnAccentFillColorPrimaryBrush}"/>
103 </StackPanel>
104 </Border>
134 <StackPanel Visibility="{x:Bind ViewModel.IsSideBarMoreContentLoadingVisible, Mode=OneWay}" Margin="0,12,0,32" HorizontalAlignment="Center" Orientation="Horizontal" Spacing="10">
135 <ProgressRing Width="20" Height="20" IsIndeterminate="True"/>
136 <TextBlock Text="加载中......" FontSize="12" Foreground="{ThemeResource TextFillColorDisabled}"/>
137 </StackPanel>
105 138 </Grid>
106 139 </ListView.Footer>
107 140 </ListView>
108 <Border Visibility="{x:Bind ViewModel.IsSideBarLoadingVisible, Mode=OneWay}" Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
141 <Border Grid.RowSpan="2" Visibility="{x:Bind ViewModel.IsSideBarLoadingVisible, Mode=OneWay}" Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
109 142 <ProgressBar Width="200" IsIndeterminate="True" HorizontalAlignment="Center" VerticalAlignment="Center"/>
110 143 </Border>
111 144 </Grid>
Modified XFENewsApplication/Views/NewsViewPage.xaml.cs +23 -0
@@ -1,5 +1,6 @@
1 1 using Microsoft.UI.Xaml.Media;
2 2 using Microsoft.UI.Xaml.Navigation;
3 using XFENewsApplication.Models;
3 4
4 5 namespace XFENewsApplication.Views;
5 6
@@ -19,6 +20,7 @@ public sealed partial class NewsViewPage : Page
19 20 ViewModel.NavigationParameterService.Initialize(this);
20 21 ViewModel.NewsListViewService.Initialize(newsSourceListView);
21 22 ViewModel.ContentListViewService.Initialize(contentListView);
23 ViewModel.DialogService.RegisterDialog(previewImageContentDialog);
22 24 }
23 25
24 26 protected override void OnNavigatedTo(NavigationEventArgs e)
@@ -34,4 +36,25 @@ public sealed partial class NewsViewPage : Page
34 36 if (ViewModel.NavigationViewService is not null)
35 37 ViewModel.NavigationViewService.ContentMargin = new(56, 24, 56, 0);
36 38 }
39
40 private void Border_PointerEntered(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
41 {
42 if (sender is Border border)
43 border.Opacity = 0.3;
44 }
45
46 private void Border_PointerExited(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
47 {
48 if (sender is Border border)
49 border.Opacity = 1;
50 }
51
52 private void imageFlipView_Tapped(object sender, Microsoft.UI.Xaml.Input.TappedRoutedEventArgs e)
53 {
54 if (e.OriginalSource is FrameworkElement image && image.DataContext is FlipImage imageSource)
55 {
56 ViewModel.PreviewImageUrl = imageSource.ImageUrl;
57 ViewModel.DialogService.ShowDialog("previewImageContentDialog");
58 }
59 }
37 60 }