我得到 en ""Dialogs must be user-initiated" 错误。
任何线索如何解决?
谢谢!
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;
}