共用方式為


Silverlight Show: 10 Laps around Silverlight 5 (Part 7 of 10)

In this article, a discussion of a few more operating system integration features in Silverlight 5 including: Default Filename for SaveFileDialog, 64-bit browser support and Power Awareness for Media Applications. Please review the Roadmap for the series before going any further.

The Roadmap for this Series

Included, the Roadmap for the series below as you may want to visit other sections as you learn Silverlight 5. I picked the following features as I thought that you may find them useful in your day-to-day work. If you want a specific topic covered then please leave it in the comments below.

  1. Introduction to SL5 – provides a brief history of Silverlight and relevant links.
  2. Binding - Ancestor Relative Source Binding and Implicit Data Templates.
  3. Graphics - XNA 3D API and Improved Graphics Stack.
  4. Media - Low-Latency Sound using XNA and Remote Control and Media Command (Keys) Support.
  5. Text - Text Tracking and Leading, Linked and Multi-column Text, OpenType Support, Pixel Snapped Text and TextOptions.
  6. Operating System Integration Part 1 - P/Invoke, Multiple Windows and Unrestricted File System Access in Full Trust.
  7. Operating System Integration Part 2 - [This Post] - Default Filename for SaveFileDialog, 64-bit browser support and Power Awareness.
  8. Productivity and Performance - XAML Binding Debugging, Parser Performance Improvements and Multi-core JIT for improved start-up time.
  9. Controls - Double and Triple click support, PivotViewer and ComboBox Type-Ahead.
  10. Other items - In-Browser HTML, PostScript and Tasks for TPL.

Default Filename for SaveFileDialog

In previous version of Silverlight, you could not specify the default filename for the SaveFileDialog message. In Silverlight 5 you can very easily.

Fire up a new Silverlight 5 project and give it any name that you want. We are going to create a simple application that contains one button and when the user clicks it the SaveFileDialog will appear with a default filename.

Switch over to the MainPage.xaml and add in the following code:

    1: <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
    2:         <Button x:Name="btnSaveFile" Content="Save File Dialog" Click="btnSaveFile_Click"/>
    3: </StackPanel>

Let’s switch back over to the MainPage.xaml.cs and add the following code to our button event handler:

    1: private void btnSaveFile_Click(object sender, RoutedEventArgs e)
    2:        {
    3:            var saveFileDialog1 = new SaveFileDialog
    4:                                      {
    5:                                          Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif",
    6:                                          DefaultFileName = "YouCanNowHaveADefaultFileName.jpeg"
    7:                                      };
    8:            saveFileDialog1.ShowDialog();
    9:        }

If we run the application now, we will see the following prompt.

Read the full post

Comments

  • Anonymous
    November 29, 2011
    November is gone, per what Scott Gu said, where's Silverlight 5?