Button 控件中的 ClickMode

Page.xaml 文件
<UserControl x:Class="SilverlightApplication2.Page"
    xmlns="http://schemas.microsoft.com/client/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <TextBlock Text="Button Training" Margin="0,20,10,15"
            FontFamily="Verdana" FontSize="14" FontWeight="Bold"
            Foreground="#FF5C9AC9" Grid.Row="0" Grid.ColumnSpan="2"/>

        <Button x:Name="btn1" Grid.Row="1" Margin ="0,5,5,5"
            HorizontalAlignment="Center"
      Foreground="Green" Width="120" Click="OnClick1"
      Content="Hover to Click" ClickMode="Hover" />
        <TextBlock x:Name="text1" Grid.Row="1" Grid.Column="1"
            Margin ="0,8,0,0" />

        <Button x:Name="btn2" Grid.Row="2" Margin ="0,5,5,5"
            HorizontalAlignment="Center"
      Foreground="Blue" Width="120" Click="OnClick2"
      Content="Press to Click" ClickMode="Press" />
        <TextBlock x:Name="text2" Grid.Row="2" Grid.Column="1"
            Margin="0,8,0,0" />

        <Button x:Name="btn3" Grid.Row="3" Margin ="0,5,5,5"
            HorizontalAlignment="Center"
      Click="OnClick3" Width="120" Content="Reset" 
            ClickMode="Release"/>
        <TextBlock x:Name="text3" Grid.Row="3" Grid.Column="1"
            Margin ="0,8,0,0" />
    </Grid>
</UserControl>

Page.xaml.cs 文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication2
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
        }

        void OnClick1(object sender, RoutedEventArgs e)
        {
            btn1.Foreground = new SolidColorBrush(Colors.Blue);
            text1.Text = "Hover.";
            text3.Text = "";
        }

        void OnClick2(object sender, RoutedEventArgs e)
        {
            btn2.Foreground = new SolidColorBrush(Colors.Green);
            text2.Text = "Click";
            text3.Text = "";
        }

        void OnClick3(object sender, RoutedEventArgs e)
        {
            btn1.Foreground = new SolidColorBrush(Colors.Green);
            btn2.Foreground = new SolidColorBrush(Colors.Blue);
            text1.Text = "";
            text2.Text = "";
            text3.Text = "Release.";
        }
    }
}

posted @ 2008-04-29 21:41  hinet  阅读(690)  评论(0编辑  收藏  举报