-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
402 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
YMCL.Main/Public/Controls/JavaNewsEntry/JavaNewsEntry.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<UserControl | ||
x:Class="YMCL.Main.Public.Controls.JavaNewsEntry" | ||
xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:asyncImageLoader="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
d:DesignHeight="450" | ||
d:DesignWidth="800" | ||
mc:Ignorable="d"> | ||
<Border | ||
Padding="10" | ||
Background="{DynamicResource 1x}" | ||
ClipToBounds="True" | ||
CornerRadius="5"> | ||
<DockPanel> | ||
<Border | ||
Width="180" | ||
Height="180" | ||
Margin="5" | ||
VerticalAlignment="Top" | ||
ClipToBounds="True" | ||
CornerRadius="5"> | ||
<asyncImageLoader:AdvancedImage Name="ImageC" /> | ||
</Border> | ||
<WrapPanel Name="WrapPanelC" Margin="10" /> | ||
</DockPanel> | ||
</Border> | ||
</UserControl> |
94 changes: 94 additions & 0 deletions
94
YMCL.Main/Public/Controls/JavaNewsEntry/JavaNewsEntry.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.Documents; | ||
using Avalonia.Markup.Xaml; | ||
using Avalonia.Media; | ||
using HtmlAgilityPack; | ||
|
||
namespace YMCL.Main.Public.Controls; | ||
|
||
public partial class JavaNewsEntry : UserControl | ||
{ | ||
public JavaNewsEntry(string img, string text) | ||
{ | ||
InitializeComponent(); | ||
ImageC.Source = "https://launchercontent.mojang.com" + img; | ||
|
||
var htmlDoc = new HtmlDocument(); | ||
htmlDoc.LoadHtml(text); | ||
|
||
var wrapPanel = WrapPanelC; | ||
|
||
// 解析并添加段落 | ||
var paragraphs = htmlDoc.DocumentNode.SelectNodes("//p"); | ||
if (paragraphs != null) | ||
{ | ||
foreach (var paragraph in paragraphs) | ||
{ | ||
var textBlock = new TextBlock | ||
{ | ||
Text = paragraph.InnerText, FontFamily = (FontFamily)Application.Current.Resources["Font"]!, | ||
TextWrapping = TextWrapping.Wrap | ||
}; | ||
wrapPanel.Children.Add(textBlock); | ||
} | ||
} | ||
|
||
// 解析并添加标题 | ||
var h1 = htmlDoc.DocumentNode.SelectSingleNode("//h1"); | ||
if (h1 != null) | ||
{ | ||
var textBlock = new TextBlock | ||
{ | ||
Text = h1.InnerText, FontWeight = FontWeight.Bold, | ||
FontFamily = (FontFamily)Application.Current.Resources["Font"]!, | ||
TextWrapping = TextWrapping.Wrap | ||
}; | ||
wrapPanel.Children.Add(textBlock); | ||
} | ||
|
||
// 解析并添加实验特性 | ||
var h2 = htmlDoc.DocumentNode.SelectSingleNode("//h2"); | ||
if (h2 != null) | ||
{ | ||
var textBlock = new TextBlock | ||
{ | ||
Text = h2.InnerText, FontWeight = FontWeight.Bold, | ||
FontFamily = (FontFamily)Application.Current.Resources["Font"]!, | ||
TextWrapping = TextWrapping.Wrap | ||
}; | ||
wrapPanel.Children.Add(textBlock); | ||
} | ||
|
||
// 解析并添加列表项 | ||
var listItems = htmlDoc.DocumentNode.SelectNodes("//ul/li"); | ||
if (listItems != null) | ||
{ | ||
foreach (var item in listItems) | ||
{ | ||
var textBlock = new TextBlock | ||
{ Text = item.InnerText, FontFamily = (FontFamily)Application.Current.Resources["Font"]!, | ||
TextWrapping = TextWrapping.Wrap }; | ||
wrapPanel.Children.Add(textBlock); | ||
wrapPanel.Children.Add(new TextBlock { Text = "\n" }); // 添加换行 | ||
} | ||
} | ||
|
||
// 解析并添加超链接 | ||
var links = htmlDoc.DocumentNode.SelectNodes("//a[@href]"); | ||
if (links != null) | ||
{ | ||
foreach (var link in links) | ||
{ | ||
var hyperlink = new HyperlinkButton() | ||
{ | ||
Content = link.InnerText, FontFamily = (FontFamily)Application.Current.Resources["Font"]!, | ||
NavigateUri = new Uri(link.Attributes["href"].Value) | ||
}; | ||
wrapPanel.Children.Add(hyperlink); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.