如何解决wpf 使进度条可从方法访问
我骑了一个代码,它将不同单词的数量放在数据网格的 txt 文件中。现在我正在尝试添加一个进度条,但我无法通过组织单词的方法访问它。不幸的是,我被告知我必须在方法中拆分、计数等(我不能在 start() 中执行此操作)。有没有人知道如何做到这一点?
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void start(object sender,RoutedEventArgs e)
{
string path = txtBox_path.Text;
string unordered = readFile(path);
var ordered = count(unordered);
progressbar_1.Maximum = ordered.Count;
foreach(var obj in ordered)
{
datagrid_table.Items.Add(obj);
progressbar_1.Value += 1;
}
}
private string readFile(string filePath)
{
string content = string.Empty;
try
{
content = File.ReadAllText(filePath);
}
catch (Exception e)
{
lbl_warning.Content=e.Message;
}
return content;
}
public static IDictionary count(string input)
{
var split = input.Split();
var grouped = split.GroupBy(x => x);
var ordered = grouped.OrderBy(x => x.Key);
var counted = from s in ordered
select new
{
word = s.Key,number = split.Where(x => x.Equals(s.Key)).Count()
};
var asList = counted.ToList();
var orderedByNumber = asList.OrderByDescending(x => x.number);
var whitespacesRemoved = orderedByNumber.Where(x => !String.IsNullOrWhiteSpace(x.word));
var asDict = whitespacesRemoved.ToDictionary(p => p.word,p => p.number);
return asDict;
}
private void stop(object sender,RoutedEventArgs e)
{
this.Close();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。