WIn_RustTools/RustTools/Views/HomePage.xaml.cs
2024-07-23 20:24:41 +08:00

116 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections.ObjectModel;
using System.Diagnostics;
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Newtonsoft.Json;
using RustTools.DataList;
using RustTools.Services;
using RustTools.ViewModels;
using Windows.UI.WindowManagement;
namespace RustTools.Views;
public sealed partial class HomePage : Page
{
public HomePageViewModel ViewModel
{
get;
}
public ObservableCollection<Contact> conns = new();
public ObservableCollection<Contact> newlist = new();
public ObservableCollection<string> Pictures { get; } = new ObservableCollection<string>();
public HomePage()
{
ViewModel = App.GetService<HomePageViewModel>();
//ÂÖ²¥Í¼
var lunbo = JsonConvert.DeserializeObject<HomeBanner>(ViewModel.lunbo);
if (lunbo != null)
{
foreach (var item in lunbo.data)
{
Pictures.Add(item.picture);
}
}
StartAsync();
InitializeComponent();
}
private void StartAsync()
{
var modListResponse = JsonConvert.DeserializeObject<ModListResponse>(ViewModel.str);
if (modListResponse == null)
{
return;
}
conns.Clear();
newlist.Clear();
foreach (var item in modListResponse.Data)
{
//https://rust.coldmint.top
if (item.Icon.Equals(""))
{
item.Icon = "/Assets/image/image.svg";
}
var contact = new Contact(item.Name, item.Description, item.UpdateTime + " " + item.CoinNumber + "´ÎÏÂÔØ")
{
ImageUrl = item.Icon.Replace("..", "https://rust.coldmint.top")
};
conns.Add(contact);
newlist.Add(contact);
}
}
public class Contact
{
public string Title
{
get; private set;
}
public string Message
{
get; private set;
}
public string Info
{
get; private set;
}
public string ImageUrl
{
get; set;
}
public Contact(string firstName, string lastName, string company)
{
Title = firstName;
Message = lastName;
Info = company;
}
}
private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
{
//var height = DisplayArea.Primary.WorkArea.Height;
//double a = height / 5;
//Debug.WriteLine(a);
//// ÉèÖÃFlipViewµÄ¸ß¶È
//Banner.Height = a;
}
private void ListAClick(object sender, ItemClickEventArgs e)
{
// »ñÈ¡±»µã»÷µÄÏî
// ´´½¨Ò»¸öеÄWindowʵÀý
Window newWindow = new Window
{
// ½«NewPageÉèÖÃΪÐÂWindowµÄÄÚÈÝ
Content = new ListViewPage(),
// ÉèÖÃÐÂWindowµÄһЩÊôÐÔ£¬Èç±êÌâºÍ´óС
Title = "New Page",
};
// ÏÔʾÐÂWindow
newWindow.Show();
}
}