-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathHitokotoControl.xaml.cs
More file actions
40 lines (37 loc) · 1.11 KB
/
Copy pathHitokotoControl.xaml.cs
File metadata and controls
40 lines (37 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Net.Http;
using System.Threading.Tasks;
using ClassIsland.Core.Controls;
using System.Windows;
using ClassIsland.Core.Abstractions.Controls;
using ClassIsland.Core.Attributes;
using MaterialDesignThemes.Wpf;
namespace HitokotoComponent
{
[ComponentInfo(
"3DFE17BA-92D3-9E14-F5CA-CC9EE40C5F58",
"一言",
PackIconKind.CalendarOutline,
"在主界面显示一言。"
)]
public partial class HitokotoControl : ComponentBase
{
private readonly HttpClient _httpClient = new HttpClient();
public HitokotoControl()
{
InitializeComponent();
LoadHitokotoAsync();
}
private async void LoadHitokotoAsync()
{
try
{
var result = await _httpClient.GetStringAsync("https://v1.hitokoto.cn/?encode=text");
Dispatcher.Invoke(() => HitokotoText.Text = result);
}
catch (HttpRequestException)
{
Dispatcher.Invoke(() => HitokotoText.Text = "加载失败");
}
}
}
}