使用已经存在的behaviors

1引入DLL

Silverlight杂记-behaviors

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");
      }
  }

Silverlight杂记-behaviors

 

 

源码下载

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

 

扩展阅读

BLEND下的Behaviors

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

相关文章:

  • 2022-02-24
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2021-08-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-27
  • 2021-06-18
  • 2021-07-02
  • 2021-12-18
  • 2021-10-22
  • 2021-07-20
相关资源
相似解决方案