Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I tried to create a toast with ProgressBar. I tried using the method in Microsoft Learn but it didn't work. #2421

Open
WillowTree1184 opened this issue Nov 7, 2023 · 0 comments
Assignees
Labels
Pri3 Topic is in the bottom 50% of page views for the repo or was not created via Feedback control.

Comments

@WillowTree1184
Copy link

WillowTree1184 commented Nov 7, 2023

I tried to create a toast with ProgressBar. I tried using the method in Microsoft Learn but it didn't work.

Please let me know what I should do.

This is my code:

public async Task Download(MinecraftDownloadInfomation DownloadInfomation)
{
    ToastContent DownloadToastContent = new ToastContentBuilder().AddText("正在下载 " + DownloadInfomation.Version).AddVisualChild(new AdaptiveProgressBar() { Title = "下载进度", Value = new BindableProgressBarValue("ProgressValue"), ValueStringOverride = new BindableString("ProgressValueString"), Status = new BindableString("ProgressStatus") }).GetToastContent();
    ToastNotification DownloadToast = new ToastNotification(DownloadToastContent.GetXml());
    string DownloadToastTag = DownloadInfomation.Version;
    string DownloadToastGroup = "HyperMinecraftLauncher-GameDownload";
    DownloadToast.Tag = DownloadToastTag;
    DownloadToast.Group = DownloadToastGroup;
    DownloadToast.Data = new NotificationData();
    DownloadToast.Data.Values["ProgressValue"] = "0";
    DownloadToast.Data.Values["ProgressValueString"] = "下载中";
    DownloadToast.Data.Values["ProgressStatus"] = "创建文件夹";
    DownloadToast.Data.SequenceNumber = 1;
    DownloadToast.SuppressPopup = false;
    ToastNotificationManager.CreateToastNotifier().Show(DownloadToast);    //this

    try
    {
        System.IO.Directory.CreateDirectory("./.minecraft/" + DownloadInfomation.Version);
    }
    catch (Exception e)
    {
        new ToastContentBuilder().AddText("我们无法为你创建游戏文件夹").AddText("游戏下载中断").AddText(e.Message).Show();
        return;
    }

    try
    {
        HttpClient Client = new HttpClient();
        Client.DefaultRequestHeaders.Accept.Clear();
        Client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/html"));
        Client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xhtml+xml"));
        Client.DefaultRequestHeaders.Add("User-Agent", ".NET Foundation Repository Reporter");
        System.IO.Stream UnprocessedManifestStream = await Client.GetStreamAsync("https://piston-meta.mojang.com/v1/packages/c18d3537d1c262a5527126b317dcf6056f7d8e4d/23w44a.json");

        using (System.IO.Stream FileStream = System.IO.File.Create("./.minecraft/" + DownloadInfomation.Version + "/" + DownloadInfomation.Version + ".json"))
        {
            await UnprocessedManifestStream.CopyToAsync(FileStream);
            UnprocessedManifestStream.Close();
        }

        string UnprocessedManifest = System.IO.File.ReadAllText("./.minecraft/" + DownloadInfomation.Version + "/" + DownloadInfomation.Version + ".json");

    }
    catch (Exception e)
    {
        new ToastContentBuilder().AddText("我们无法为你下载游戏核心文件").AddText("游戏下载中断").AddText(e.Message).Show();
        return;
    }
}

When I call this function, it doesn't pop up a toast as expected.

image

@issues-automation issues-automation bot added the Pri3 Topic is in the bottom 50% of page views for the repo or was not created via Feedback control. label Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pri3 Topic is in the bottom 50% of page views for the repo or was not created via Feedback control.
Projects
None yet
Development

No branches or pull requests

2 participants