다음을 통해 공유


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

In this article, a discussion of several new features/controls such as Double and Triple click support, PivotViewer and ComboBox Type-Ahead. 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 - 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 - [This Post] - Double and Triple click support, PivotViewer and ComboBox Type-Ahead.
  10. Other items - In-Browser HTML, PostScript and Tasks for TPL

Double and Triple Click Support

One of the new features in Silverlight 5 is the ability to use Double and Triple Click Support. This functionality will tell you how many times the user has clicked the mouse button. The property is called ClickCount and resides in the MouseButtonEventArgs class. Let’s take a look at how to use this new feature.

Fire up a new Silverlight 5 project and give it any name that you want.

Switch over to the MainPage.xaml.cs and add the following code: (Note: You may not need the MainPage() Method section)

    1: public MainPage()
    2: {
    3:     InitializeComponent();
    4: }
    5:  
    6: private void textBlock1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    7: {
    8:     textBlock1.Text = e.ClickCount.ToString();
    9: }

Switch back over to the MainPage.xaml and add in the following code replacing the current Grid:

    1: <Grid x:Name="LayoutRoot" Background="White">
    2:       <Border BorderBrush="Black" BorderThickness="1" Margin="52,49,68,74" CornerRadius="10">
    3:           <TextBlock Height="152" HorizontalAlignment="Center" x:Name="textBlock1" Text="0" VerticalAlignment="Center" Width="244" MouseLeftButtonDown="textBlock1_MouseLeftButtonDown" Foreground="#FFFF2E2E" FontSize="96" TextAlignment="Center" />
    4:       </Border>
    5: </Grid>

If we go ahead and run the application then we will see the following application.

SNAGHTMLf7d6db1

Go ahead and begin clicking inside of the border and you will see the number increase. If you wait a few seconds and click again then you will notice that it reset itself. You could easily add If..Then… statements to determine what click count number they are on. This may be helpful for a 35 click Easter egg. :)

 

Read the full post