SharePoint Experts, Information Architects, Expert Witness

We provide consulting in a broad array of business and technology from architecture to design to deployment of global systems with a focus on surfacing data in the enterprise. Specialists in Microsoft, we are a premier provider of SharePoint Expertise (including 2016 and Office 365). We also provide Expert Witness/Legal Expert in eDiscovery, source discovery, patent infringement, piracy and more! We also have established SICG DLDS s.a. - our counterpart in Costa Rica that specializes in water systems (http://www.crwatersolutions.com) - Contact me direct: david_sterling@sterling-consulting.com or call 704-873-8846 x704.

Search This Blog

Monday, November 29, 2010

Troubles using Dialog Boxes in Silverlight

I've often come across this but after working on a long project, often forget the basics - as in using Dialog boxes for File operations. The stanard error is "Dialogs must be user-initiated" which is a little off from the point - you'd expect that a click event could also open a dialog however it is because the threading (context) of the Dialog would be lost in the event.

The solution is simple - simply put all of the Dialog logic in its own method and call the method from the click event:

private void ExportFile_Click(object sender, RoutedEventArgs e)
{
              ExportTheFile();
}

private void ExportTheFile();
{
     SaveFileDialog SFD = new SaveFileDialog();
     SFD.DefaultExt = "*.txt";
     SFD.Filter = "Text (*.txt) | *.txt|All files (*.*)|*.*";
     if (SFD.ShowDialog())
     {
            StreamWriter OutStream = new StreamWriter(SFD.OpenFile());
            ...
      }
}

No comments: