silverlight   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Silverlight 创建自定义外观的按钮大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

前面一篇博客“WPF/Silverlight 控件的基本组成” 介绍了创建控件模板的一些基础知识,这篇是一个简单演示,演示一个不规则的按钮。 为了简单期间,我们只定义了按钮的鼠标移动到上面以及鼠标点击两个特效。其他特效没有定义。 演示效果如下: 对应Xaml代码,代码中已经增加了注释,如果前一篇博客阅读过,对代码的阅读就没有难度,代码如下: <UserControl xmlns="http:/

前面一篇博客WPF/Silverlight 控件的基本组成” 介绍了创建控件模板的一些基础知识,这篇是一个简单演示,演示一个不规则的按钮。

为了简单期间,我们只定义了按钮的鼠标移动到上面以及鼠标点击两个特效。其他特效没有定义。

演示效果如下:

对应Xaml代码代码中已经增加了注释,如果前一篇博客阅读过,对代码的阅读就没有难度,代码如下:

<UserControl
	xmlns="http://scheR_555_11845@as.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://scheR_555_11845@as.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://scheR_555_11845@as.microsoft.com/expression/blend/2008" xmlns:@H_396_33@mc="http://scheR_555_11845@as.openxmlformats.org/markup-compatibility/2006"
	x:Class="SilverlightApplication_IrregularButton.MainPage"
	Width="250" Height="150" @H_396_33@mc:Ignorable="d">
	<UserControl.resources>
		
  
  
		<ControlTemplate x:Key="ButtonControlTemplate1" TargetType="Button">
			<Grid>
				<VisualStateManager.VisualStateGroups>
					<VisualStateGroup x:Name="FocusStates">
						<VisualState x:Name="Focused"/>
						<VisualState x:Name="Unfocused"/>
					
  
  VisualStateGroup>
					<VisualStateGroup x:Name="CommonStates">
						<VisualState x:Name="Normal"/>
						
						<VisualState x:Name="MouSEOver">
							 
   
							<Storyboard>
								<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="path" 
								Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
									<EasingDoubleKeyFrame KeyTime="00:00:00" Value="1.1"/>
								 
   DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="path" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"> <EasingDoubleKeyFrame KeyTime="00:00:00" Value="1.1"/>  
    DoubleAnimationUsingKeyFrames>  
     Storyboard>  
      VisualState> <VisualState x:Name="Pressed">  
        <Storyboard> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="path" Storyboard.TargetProperty="(UIElement.opacitymask).(GradientBrush.GradientStops)[0].(GradientStop.offset)"> <EasingDoubleKeyFrame KeyTime="00:00:00" Value="0.4"/>  
       DoubleAnimationUsingKeyFrames>  
        Storyboard>  
         VisualState> <VisualState x:Name="Disabled"/>  
          VisualStateGroup>  
           VisualStateManager.VisualStateGroups> <Path x:Name="path" Stretch="Fill" stroke="{TemplateBinding BorderBrush}" strokeThickness="2" @H_396_33@margin="10.652,1.073,8,0" UseLayoutRounding="false" Data="M36.891956,9.7781897 C64.593346,-11.270991 79.772194,-3.6822519 95.642052,17.778385 C176.95827,15.002772 153.51022,23.269783 98.359367,44.312874 C81.101433,49.818928 46.730473,42.151268 47.980583,38.40152 C28.298779,43.241684 7.1613593,35.330677 36.891956,9.7781897 z" RenderTransformOrigin="0.5,0.5" Fill="{TemplateBinding BACkgrounD}" > <Path.opacitymask> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="White" Offset="1"/> <GradientStop Color="#26FFFFFF"/>  
            LinearGradientBrush>  
             Path.opacitymask> <Path.RenderTransform> <TransformGroup> <ScaleTransform/> <SkewTransform/> <RotateTransform/> <TranslateTransform/>  
              TransformGroup>  
               Path.RenderTransform>  
                Path> <ContentPresenter @H_396_33@margin="33,18,72,18"/>  
                 Grid>  
                  ControlTemplate>  
                    <Style x:Key="IrregularButton" TargetType="Button"> <Setter Property="Template" Value="{Staticresource ButtonControlTemplate1}"/> <Setter Property="BACkground" Value="#FFA56B16"/> <Setter Property="Foreground" Value="#FF000000"/>  
                   Style>  
                    UserControl.resources> <Grid x:Name="LayoutRoot" BACkground="White">  
                     @H_456_674@ <Button Style="{Staticresource IrregularButton}" Content="Button1" Foreground="#FF2431C2" BACkground="#FFBA730A" BorderBrush="#FF111695" Height="70" Width="180"/>  
                     Grid>  
                      UserControl>

 

资料:

Silverlight2 边学边练 之七 模板与状态
http://www.cnblogs.com/gnielee/archive/2009/08/03/1537929.html

一步一步学Silverlight 2系列(9):使用控件模板
http://www.cnblogs.com/Terrylee/archive/2008/03/08/Silverlight2-step-by-step-part9-using-control-template.html

理解silverlight 2.0中的Templated Control
http://silverlight.cn/index.php?q=node/597

演练:使用 ControlTemplate 自定义按钮的外观
http://msdn.microsoft.com/zh-cn/library/cc903963(VS.95).aspx

Control Templates
http://silverlight.net/learn/quickstarts/controltemplates/

通过使用 ControlTemplate 自定义现有控件的外观
http://msdn.microsoft.com/zh-cn/library/cc189093(VS.95).aspx

创建系统控件的可重用模板
http://msdn.microsoft.com/zh-cn/library/dd185509.aspx

@H_419_772@

大佬总结

以上是大佬教程为你收集整理的Silverlight 创建自定义外观的按钮全部内容,希望文章能够帮你解决Silverlight 创建自定义外观的按钮所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。