使用复选框异步下载

时间:2018-10-05 06:11:25

标签: c# asynchronous checkbox download

我创建了一个WPF C#gui,它应该可以作为工具的多个下载器。每个应用程序的复选框和一个下载按钮。 有人能帮我启动下载代码的工作吗?是C#的新手,虽然我在Google上搜索了很多东西,但仍然找不到适合我的情况的东西。 下载按钮应选中所有复选框,然后异步下载文件。 预先感谢

private void Button_Click(object sender, RoutedEventArgs e)
    {
        if (ccleaner.IsChecked == true)
        {
            string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string url = "https://www.ccleaner.com/ccleaner/download/portable/downloadfile";
            string filename = "ccleaner.zip";
            using (WebClient wc = new WebClient())
            {
                wc.DownloadFileAsync(new Uri(url), desktopPath + "/" + filename);
            }
        }

我遇到的错误是:mainwindow.xaml wich的第10行上应该有这样的方法名称:

<CheckBox x:Name="ccleaner" Content="ccleaner" HorizontalAlignment="Left" Margin="197.883,90.123,0,0" VerticalAlignment="Top" Checked="ccleaner"/>

1 个答案:

答案 0 :(得分:0)

正如auburg所说,我必须从我的xaml代码中删除“ Checked =“ ccleaner””。 抱歉,我无法将他的评论标记为解决方案