System.Windows.Controls.Button   button控件
一、button控件的各种样式的展示
可以通过
<phone:PhoneApplicationPage.Resources>
<Style x:Key="ButtonStyle1" TargetType="Button">
……
</Style>
……
</phone:PhoneApplicationPage.Resources>
来给控件定义公共的样式
调用样式的方法:在Button控件上添加样式的属性 Style="{StaticResource ButtonStyle1}"

<Button Content="前往下一頁" Height="88" HorizontalAlignment="Left" Margin="160,513,0,0" Name="button2" VerticalAlignment="Top" Width="288" Click="button2_Click" />

Margin属性定义了Button控件的相对整体界面的于左上右下的距离。
Height控件的高度
Width控件的宽度
Content控件显示的内容
Click单击触发的事件
HorizontalAlignment水平位置
VerticalAlignment垂直位置

MainPage.xaml

代码


<phone:PhoneApplicationPage
x:Class="buttonDemo.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True" >
<!--定义公共的样式-->
<phone:PhoneApplicationPage.Resources>
<Style x:Key="ButtonStyle1" TargetType="Button">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/>
<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/>
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
<Setter Property="Padding" Value="10,3,10,5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="15" Margin="{StaticResource PhoneTouchTargetOverhang}">
<ContentPresenter Margin="5,11" d:LayoutOverrides="Height" HorizontalAlignment="Center"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ButtonStyle2" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Border BorderBrush="Black" BorderThickness="1" Background="#FF0054FB" CornerRadius="15">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="Bottom" Margin="0,0,0,7"/>
</Border>
<Border BorderThickness="1" CornerRadius="15,15,0,0" Margin="0,0,0,48">
<Border.Background>
<LinearGradientBrush EndPoint="0.506,0.8" StartPoint="0.507,0.05">
<GradientStop Color="#19FFFFFF" Offset="0.996"/>
<GradientStop Color="#BFFFFFFF"/>
</LinearGradientBrush>
</Border.Background>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</phone:PhoneApplicationPage.Resources>

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0,0,0">
<Button Content="button" Height="88" HorizontalAlignment="Left" Margin="20,8,0,0" Name="button1" VerticalAlignment="Top" Width="410" />
<Button Content="圓角按鈕" Height="84" Margin="0,118,38,0" VerticalAlignment="Top" Style="{StaticResource ButtonStyle1}" HorizontalAlignment="Right" Width="398"/>
<Button Content="Button" Margin="20,224,26,0" Height="84" VerticalAlignment="Top" Foreground="Black">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF0010FF"/>
<GradientStop Color="White" Offset="0.664"/>
<GradientStop Color="#FF6D73D2" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button Content="前往下一頁" Height="88" HorizontalAlignment="Left" Margin="160,513,0,0" Name="button2" VerticalAlignment="Top" Width="288" Click="button2_Click" />
<Button Content="Button" HorizontalAlignment="Right" Height="108" Margin="0,0,168,168" Style="{StaticResource ButtonStyle2}" VerticalAlignment="Bottom" Width="128" Click="Button_Click" />
</Grid>
</Grid>
</phone:PhoneApplicationPage>

private void button2_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative));//导航创建新的页面  
        }

private void Button_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("button click");//弹出对话框
        }

二、旋转的按钮控件

SecondPage.xaml

代码

<phone:PhoneApplicationPage
x:Class="buttonDemo.SecondPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button x:Name="btnCreateButton" Content="產生按鈕" Height="74" Margin="0,8,0,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="210" Click="btnCreateButton_Click" />
<TextBox x:Name="txtCount" Height="68" Margin="181,8,204,0" TextWrapping="Wrap" Text="10" VerticalAlignment="Top"/>
<Canvas x:Name="cvContent" Margin="8,88,8,96"/>
<Button Content="前往下一頁" Height="88" HorizontalAlignment="Left" Margin="168,519,0,0" Name="button2" VerticalAlignment="Top" Width="288" Click="button2_Click" />
<TextBlock HorizontalAlignment="Left" Height="29" Margin="89,30,0,0" TextWrapping="Wrap" Text="按鈕數量" VerticalAlignment="Top" Width="92"/>
</Grid>
</Grid>

</phone:PhoneApplicationPage>

private void btnCreateButton_Click(object sender, RoutedEventArgs e)
        {
            cvContent.Children.Clear();

for (int i = 0; i < Convert.ToInt32(txtCount.Text); i++)
            {            
                Button newBtn = new Button();//创建Button控件
                newBtn.Name = "btn" + i.ToString();
                Canvas.SetLeft(newBtn, cvContent.ActualWidth / 2);//画布控件Canvas
                Canvas.SetTop(newBtn, cvContent.ActualHeight / 2);

newBtn.Background = new SolidColorBrush(Colors.Orange);//背景颜色
                newBtn.Content = "button-" + i.ToString();//按钮显示的内容
                newBtn.RenderTransformOrigin = new Point(0, 0);

RotateTransform rt = new RotateTransform();//System.Windows.Media下的旋转控件
                rt.Angle = i * (360 / Convert.ToInt32(txtCount.Text));//角度
                newBtn.RenderTransform = rt;

cvContent.Children.Add(newBtn);
            }
        }

private void Test()
        {
            Storyboard a = new Storyboard();
           
        }

private void button2_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/ThirdPage.xaml", UriKind.Relative));
        }

三、会动的按钮控件

ThirdPage.xaml

代码

<phone:PhoneApplicationPage
x:Class="buttonDemo.ThirdPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">
<phone:PhoneApplicationPage.Resources>
<Storyboard x:Name="Storyboard1">
<DoubleAnimation Duration="0:0:0.4" To="13" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" AutoReverse="True" Storyboard.TargetName="button1" d:IsOptimized="True"/>
</Storyboard>
</phone:PhoneApplicationPage.Resources>

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button Content="Button" HorizontalAlignment="Left" Margin="71,240,0,270" Name="button1" Width="346" RenderTransformOrigin="0.5,0.5" d:LayoutOverrides="VerticalAlignment" >
<Button.RenderTransform>
<CompositeTransform/>
</Button.RenderTransform>
</Button>
<Button Content="轉吧,按鈕" Height="74" HorizontalAlignment="Left" Margin="182,6,0,0" Name="button2" VerticalAlignment="Top" Width="274" Click="button2_Click" />
</Grid>
</Grid>
</phone:PhoneApplicationPage>

private void button2_Click(object sender, RoutedEventArgs e)
        {
            Storyboard1.Stop();
           
            //(Storyboard1.Children[0] as DoubleAnimation).From = 0;
            //(Storyboard1.Children[0] as DoubleAnimation).To = 150;
            //Storyboard.SetTargetName( Storyboard1,  "button1");
            Storyboard1.Begin();

}

Windows Phone 7 button控件相关推荐

  1. [视频]Silverlight for Windows Phone 7基本开发过程以及Push Button控件的使用

    简介 通过视频的方式讲述Silverlight for Windows Phone 7基本开发过程以及Push Button控件的使用,同时讲述Silverlight for Windows Phon ...

  2. 【第3版emWin教程】第55章 emWin6.x按钮Button控件自定义回调函数,实现各种按钮效果

    教程不断更新中:链接 第55章       emWin6.x按钮Button控件自定义回调函数,实现各种按钮效果 本章节为大家讲解按钮控件自定义回调函数,通过其回调函数就可以实现各种按钮效果.这方面的 ...

  3. Python Tkinter教程(二)——Label控件、Frame控件、Button控件的完整参数和所有方法及详细用法

    >>>[上节回顾:tkinter编程基本步骤.窗口基本属性及Toplevel控件的使用]<<< Python Tkinter教程(二)         这篇博客将详 ...

  4. 11. Windows应用程序常用控件

    Windows应用程序常用控件 1 控件概述 1.1 控件的分类及作用 1.2 控件的命名规范 1.2 控件的相关操作 2.1 添加控件 2.2 对齐控件 2.3 锁定控件 2.4 删除控件 3 文本 ...

  5. Android UI 统一修改Button控件的样式,以及其它系统控件的默认样式

    先介绍下修改原理:首先打开位于android.widget包下面的Button.java文件,这里有一句关键的代码如下: public Button(Context context, Attribut ...

  6. 设置Button控件创建完毕时触发的事件.

    Button控件的creationCompleteEffect样式. 示例: 刷新查看效果. 代码: <?xml version="1.0" encoding="u ...

  7. Button控件的基本使用(初识封装、减少代码冗余性、代码优化)

    Button是程序用于和用户进行交互的一个重要控件,它的配置属性和TextView差不多,这里我们可以注意观察一下Button众多属性中的两种: 1.属性名android:textAllCaps    ...

  8. ASP.NET Button控件的UseSubmitBehavior属性引发的血案

    这里先不说标题上的UseSubmitBehavior属性是什么,先说下面这种情况. 通常,在我们写一个表单页面的时候,最下方会有"提交"和"返回"字样的两个按钮 ...

  9. Windows 8.1 新增控件之 DatePicker

    Windows 8.1 新增控件之 DatePicker 原文:Windows 8.1 新增控件之 DatePicker 大年初一来介绍一个简单易用的DatePicker 控件,这个控件是新增的?印象 ...

最新文章

  1. C语言实现RC4序列密码
  2. 你还在new对象吗?Java8通用Builder了解一下?
  3. maven 错误:HttpServlet was not found on the Java
  4. 错误: 程序包r2不存在_坚果 R2 使用体验:它是一款真旗舰,也是不一样的旗舰...
  5. 如何拓展外链引流,让网站成为“顶牛”?
  6. (并查集 建立关系)食物链 -- POJ-- 1182
  7. 高性能IO -Reactor模式的实现
  8. 手把手系列:(一)用Benchmarksql测试Oracle数据库性能
  9. 【C/C++10】天气APP:MySQL/PostgreSQL,环境变量/动静态库,Linux/Oracle字符集
  10. asp.net core自定义依赖注入容器,替换自带容器
  11. mysql定义shell变量_shell 变量的定义,赋值,运算
  12. NPAPI:JS的Number,在接口中可能是int32,也可能是double
  13. stc15f2k60f2单片机定时器_STC15F2K60S2系列
  14. 2021年全年详细工作日、周末、节假日数据表sql_excel
  15. Day9-Python文本数据(DataWhale)
  16. 建立良好人际关系的原则
  17. 学习理论-PAC理论
  18. 有关于win10系统不能更改自己ip得问题解决办法
  19. CSP 寻宝!大冒险! C++
  20. 苹果android通用插头,苹果充电器插头可以给安卓手机用吗??

热门文章

  1. Lync 客户端功能对比之IM功能
  2. 刷排名软件使用中需要用到的seo基础知识
  3. 求救数据库高手~~急急。。。
  4. linux消息队列总结
  5. JAVA-SWING:生成透明JTable
  6. 高级版本 【多后台】
  7. Weka算法Classifier-tree-J48源代码分析(一个)基本数据结构和算法
  8. Python学习之路-基础知识1
  9. linux下定时执行任务方法【转】
  10. 网络安全之***手法计中计