我得到“”对话必须是用户启动的“错误。
有任何解决方法可以解决吗?
谢谢!
private void ExportDataToCSV()
{
string separator = GetSeparator();
LoadClientContentItemStatistics(); // async. request of MVVM Light Toolkit
foreach (var item in this._view)
{
sb.AppendLine("\"" + item.Player.PlayerGroup.Name + "\"" + separator + "\"" + item.Player.Name + "\"" + separator + "\"" + item.ClientContentItem.Name + "\"" + separator + "\"" + item.TotalTime.ToString() + "\"" + separator + "\"" + item.TotalQuantity.ToString() + "\"" + separator + Environment.NewLine);
}
SaveFileDialog sfd = new SaveFileDialog()
{
DefaultExt = "csv",
Filter = "CSV Files (*.csv)|*.csv|All files (*.*)|*.*",
FilterIndex = 1
};
if (sfd.ShowDialog() == true) // "Dialogs must be user-initiated" ERROR
{
using (Stream stream = sfd.OpenFile())
{
using (StreamWriter writer = new StreamWriter(stream))
{
writer.Write(sb.ToString());
writer.Close();
}
stream.Close();
}
}
IsExport = true;
}
答案 0 :(得分:3)
此错误意味着它所说的内容:用户必须启动此对话框。因此,您只能从用户点击事件或其他用户发起的事件中调用此方法。