Silverlight学习笔记基本控件(三)

关于Button综合示例:

前台代码:

<UserControl x:Class="ButtonDemo.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" Loaded="UserControl_Loaded">

    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel Width="400">
           
       
            <Button Content="普通按钮" Grid.Column="0"></Button>
        <Button  Grid.Column="1">
            <Button.Content>
                <StackPanel Orientation="Horizontal">
                <TextBlock Text="这是组合成的按钮" VerticalAlignment="Center"></TextBlock>
                    <Image Source="1135203.jpg" Width="30" Height="30"  VerticalAlignment="Center"></Image>
                </StackPanel>
            </Button.Content>
        </Button>
            <Button>
                <Button.Content>
                    <StackPanel >
                    <TextBlock Text="两部分组成的按钮">
                       
                    </TextBlock>
                    <Line Stroke="Red" StrokeThickness="2" X1="0" Y1="10" X2="80" Y2="10"></Line>
                        <TextBlock Text="这是下半部分"></TextBlock>
                    </StackPanel>
                </Button.Content>
            </Button>
        <ToggleButton Grid.Row="1" Grid.Column="0" Height="40" Width="80" IsThreeState="True" Content="三状态的按钮" x:Name="togBtnTest" Click="togBtnTest_Click"></ToggleButton>
            <RepeatButton Interval="1" Content="连续触发的按钮" x:Name="repeatBtn" Click="RepeatButton_Click"></RepeatButton>
            <HyperlinkButton  NavigateUri="http://www.google.com.hk" Content="普通HyperlinkButton" TargetName="_blank" Cursor="Hand"/>
            <StackPanel Orientation="Vertical">
            <RadioButton GroupName="test1"  VerticalAlignment="Center">
                <RadioButton.Content>
                    <StackPanel  Orientation="Horizontal">
                        <TextBlock Text="男" VerticalAlignment="Top"></TextBlock>
                            <Image Source="1135203.jpg"  VerticalAlignment="Top" Width="40" Height="40"></Image>
                    </StackPanel>
                </RadioButton.Content>
            </RadioButton>
            <RadioButton GroupName="test1"  VerticalAlignment="Center">
                <RadioButton.Content>
                    <StackPanel Orientation="Horizontal">
                            <TextBlock Text="女"  VerticalAlignment="Top"></TextBlock>
                            <Image Source="1135203.jpg"  VerticalAlignment="Top" Width="40" Height="40"></Image>
                    </StackPanel>
                </RadioButton.Content>
              
            </RadioButton>
               
            </StackPanel>
          
        </StackPanel>
    </Grid>
</UserControl>

后台代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
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 ButtonDemo
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }
        /// <summary>
        /// togBtnTest点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void togBtnTest_Click(object sender, RoutedEventArgs e)
        {
            switch (togBtnTest.IsChecked) {
                case true:
                    this.togBtnTest.Content = "当前被选中";
                    break;
                case false:
                    this.togBtnTest.Content = "当前未被选中";
                    break;
                default:
                    this.togBtnTest.Content = "当前未激活";
                    break;
            }
        }
        //控件加载完成时为togBtnTest设置状态
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            this.togBtnTest.Content = "未激活";
        }
        int clickTimes = 0;
        private void RepeatButton_Click(object sender, RoutedEventArgs e)
        {
            clickTimes++;
            repeatBtn.Content = clickTimes.ToString();
        }
    }
}

你可能感兴趣的:(silverlight)