Supporting both Double and Triple Click in Silverlight 5
I.Introduction:
– Silverlight 5 hổ trợ rất nhiều tính năng mới, và tính năng đếm số lần Click chuột cũng là một trong số đó. Với tính năng này chúng ta sẽ quản lý được việc User Click bao nhiêu lần chuột vào ứng dụng(hay một Control nào đó).
– Trong bài này mình xin chia sẻ cách sử dụng Tính năng đếm số lần Click chuột trong Silverlight.
II.Creating Project And Coding:
Trước tiên chúng ta tạo một giao diện đơn giản như đoạn XAML sau:
1: <UserControl x:Class="DoubleTripleClickinSilverlight5.MainPage"
2: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4: xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5: xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6: mc:Ignorable="d"
7: d:DesignHeight="300" d:DesignWidth="400">
8:
9: <Grid x:Name="LayoutRoot" Background="White">
10: <Grid.RowDefinitions>
11: <RowDefinition Height="70"/>
12: <RowDefinition Height="30"/>
13: <RowDefinition Height="Auto"/>
14: </Grid.RowDefinitions>
15: <TextBlock Text="Double and Triple Click in Silverlight 5"
16: FontSize="18" Grid.Row="0" />
17: <StackPanel Grid.Row="1" Name="MyStackPanel">
18: <StackPanel.Background>
19: <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
20: <GradientStop Color="Black" Offset="0" />
21: <GradientStop Color="White" Offset="1" />
22: </LinearGradientBrush>
23: </StackPanel.Background>
24: <TextBlock HorizontalAlignment="Left" Foreground="White"
25: FontSize="18" Name="lbl_Text"/>
26: </StackPanel>
27: <Rectangle Name="rect" Grid.Row="2" Margin="1,1,1,-198"
28: MouseLeftButtonDown="rect_MouseLeftButtonDown" Height="199">
29: <Rectangle.Fill>
30: <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
31: <GradientStop Color="#FFB6D1B6" Offset="0" />
32: <GradientStop Color="WhiteSmoke" Offset="1" />
33: </LinearGradientBrush>
34: </Rectangle.Fill>
35: </Rectangle>
36: </Grid>
37: </UserControl>
Code C#:
1: namespace DoubleTripleClickinSilverlight5
2: {
3: public partial class MainPage : UserControl
4: {
5: public MainPage()
6: {
7: InitializeComponent();
8: }
9:
10: private void rect_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
11: {
12: lbl_Text.Text = "Click Count: " + e.ClickCount.ToString();
13: }
14: }
15: }
Sau khi chạy ứng dụng:khi Chúng ta Click một lần thì Ứng dụng sẽ đếm số lần Click cho chúng ta.
-Tính năng mới này rất hay, giải quyết được vấn đề Double Click, Triple Click …….
-chúng ta chỉ cần dùng thuộc tính ClickCount là đã quản lý được số lần Click
/*Web is beautiful*/