zoukankan      html  css  js  c++  java
  • Silverlight杂记behaviors

    使用已经存在的behaviors

    1引入DLL

    image

    2在XAML中添加行为,

    在这里添加了2个,一个是拖动,一个是缓动效果

    <Rectangle x:Name="PurpleSquare" 
                    Height
    ="20" 
                    Width
    ="20" 
                    HorizontalAlignment
    ="Left" 
                    VerticalAlignment
    ="Top" 
                    Margin
    ="20" 
                    Fill
    ="BlueViolet"> 
            
    <i:Interaction.Behaviors>
               
    <ei:MouseDragElementBehavior> 拖拽效果行为
                   
    </ei:MouseDragElementBehavior>

                
    <ei:FluidMoveBehavior Duration="0:0:4">缓动 
                    
    <ei:FluidMoveBehavior.EaseX> 
                        
    <ElasticEase EasingMode="EaseOut" 
                                        Oscillations
    ="3" 
                                        Springiness
    ="4" /> 
                    
    </ei:FluidMoveBehavior.EaseX> 
                    
    <ei:FluidMoveBehavior.EaseY> 
                        
    <ElasticEase EasingMode="EaseOut" 
                                        Oscillations
    ="3" 
                                        Springiness
    ="4" /> 
                    
    </ei:FluidMoveBehavior.EaseY> 
                
    </ei:FluidMoveBehavior> 
            
    </i:Interaction.Behaviors>

    private void StartMove_Click(object sender, RoutedEventArgs e) { 
             Thickness margin 
    = PurpleSquare.Margin; 
             margin.Left 
    += 100
             margin.Top 
    += 100;
             PurpleSquare.Margin 
    = margin; 
         }

     

    自定义behaviors

    public class CustomBehavior : Behavior<Button>
      {
          protected override void OnAttached()
          {
              base.OnAttached();
              AssociatedObject.Click += new RoutedEventHandler(OnButtonClick);
          }

          protected override void OnDetaching()
          {
              base.OnDetaching();
              AssociatedObject.Click -= OnButtonClick;
          }

          void OnButtonClick(object sender, RoutedEventArgs e)
          {
              MessageBox.Show("自定义行为-!  MessageBox.Show");
          }
      }

    image

    源码下载

    https://files.cnblogs.com/facingwaller/Behaviors.rar

    扩展阅读

    BLEND下的Behaviors

    http://www.cnblogs.com/jv9/archive/2010/04/03/1703554.html

  • 相关阅读:
    MOSS 2007(Designer) 自定义列表表单开发笔记1(表单字段控件格式化)
    不使用第三个变量,怎么交换两个变量的值?
    AT指令介绍
    转:iis 支持wap
    WAP传输协议
    计算生肖
    下载文件 转
    彩信MO,MT的业务流程(转)
    最详细AT指令
    WML标签手册
  • 原文地址:https://www.cnblogs.com/facingwaller/p/1917295.html
Copyright © 2011-2022 走看看