惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
J
Java Code Geeks
M
MIT News - Artificial intelligence
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
MongoDB | Blog
MongoDB | Blog
G
Google Developers Blog
Engineering at Meta
Engineering at Meta
量子位
S
SegmentFault 最新的问题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
A
About on SuperTechFans
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
Recent Announcements
Recent Announcements
腾讯CDC
I
InfoQ
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
Blog — PlanetScale
Blog — PlanetScale
H
Help Net Security
爱范儿
爱范儿

博客园 - civ3's .NET studying

Comet in IE comet研究 动态加载Web Service - civ3's .NET studying IIS.pk(vs2005)==Mutex - civ3's .NET studying [Reading]THIRD BASE 良性克服Firefox跨站 Notify Server 战国[节选] Merssenger线程通讯图 Ajax.NET关键 Ajax多线程 Merssenger构想与原型开发[0] CTeX学习散列 多媒体杂志 [Discovery]msn space trackbackable! MyText RAR控制台日常备份策略 Easy Binding(DataContext,TwoWay) WPF自学方法
HTC到StoryBoard——DHTML迁移到WPF(二)
civ3's .NET studying · 2006-02-12 · via 博客园 - civ3's .NET studying

下载:https://files.cnblogs.com/civ3/storyBoard.rar

微软支持HTML组件技术HTC,但是安全和性能都有一定缺陷。在WPF中,利用StoryBoard可以快速实现一些以前需要用HTC才能较好实现的DHTML效果。
以下两个例子都很简单只是为了说明问题:
复用
DHTML:Style(+behavior)
WPF:Resource
形状
DHTML:VML的Shape,或DIV矩形
WPF:Rectangle
事件与行为
DHTML:Event.element用JS脚本
WPF:丰富的故事板特性

以下是源程序
DHTML

<html><head>
<style type="text/css">
.oStyle
{
    behavior
:url(storyBoard.htc);
    background-color
:Blue;
}

</style>

<title>Civ3's testing on Storyboard</title>
</head>
<body>
<div style="width:100px; height:100px;" class="oStyle"></div>
</body></html>

.htc

<PUBLIC:ATTACH EVENT="onmouseover" ONEVENT="mouseover()"/> 
<PUBLIC:ATTACH EVENT="onmouseout" ONEVENT="mouseout()"/> 
<PUBLIC:ATTACH EVENT="onmousedown" ONEVENT="mousedown()"/> 
<PUBLIC:ATTACH EVENT="onmouseup" ONEVENT="mouseup()"/>
<SCRIPT LANGUAGE="JScript">
    
function mouseover(){
    event.srcElement.style.backgroundColor
='red'; 
}

function mouseout(){
    event.srcElement.style.backgroundColor
='blue'; 
    event.srcElement.style.width
=100;
}

function mousedown(){
    event.srcElement.style.width
=110
}

function mouseup(){
    event.srcElement.style.width
=100;
}

</SCRIPT>

XAML

<Page xmlns="http://schemas.microsoft.com/winfx/avalon/2005" 
  xmlns:x
="http://schemas.microsoft.com/winfx/xaml/2005"
  WindowTitle
="Civ3's testing on Storyboard">
<Page.Resources>
 
<Style TargetType="{x:Type Rectangle}" x:Key="oStyle">
    
<Setter Property="Rectangle.Fill">
        
<Setter.Value>
          
<SolidColorBrush Color="Blue"/>
        
</Setter.Value>
    
</Setter>
    
<Style.Triggers>
     
<EventTrigger RoutedEvent="Rectangle.MouseEnter">
      
<EventTrigger.Actions>
          
<BeginStoryboard>
            
<Storyboard>              
              
<ColorAnimation 
                
Storyboard.TargetProperty="(Rectangle.Fill).(SolidColorBrush.Color)"
                From
="Blue" To="Red" Duration="0:0:.5" />  
            
</Storyboard>
          
</BeginStoryboard>
      
</EventTrigger.Actions>
         
</EventTrigger>

     
<EventTrigger RoutedEvent="Rectangle.MouseLeave">
      
<EventTrigger.Actions>
          
<BeginStoryboard>
            
<Storyboard>              
              
<ColorAnimation 
                
Storyboard.TargetProperty="(Rectangle.Fill).(SolidColorBrush.Color)"
                To
="Blue" Duration="0:0:.5" />
        
<DoubleAnimation
            
Storyboard.TargetProperty="Width"
        To
="100" Duration="0:0:.2" />
            
</Storyboard>

          
</BeginStoryboard>
      
</EventTrigger.Actions>
         
</EventTrigger>

     
<EventTrigger RoutedEvent="Rectangle.MouseDown">
      
<EventTrigger.Actions>
          
<BeginStoryboard>
            
<Storyboard>              
              
<DoubleAnimation
            
Storyboard.TargetProperty="Width"
        By
="10" Duration="0:0:.2" />  
            
</Storyboard>
          
</BeginStoryboard>
      
</EventTrigger.Actions>
         
</EventTrigger>

     
<EventTrigger RoutedEvent="Rectangle.MouseUp">
      
<EventTrigger.Actions>
          
<BeginStoryboard>
            
<Storyboard>              
              
<DoubleAnimation
            
Storyboard.TargetProperty="Width"
        To
="100" Duration="0:0:.2" />  
            
</Storyboard>
          
</BeginStoryboard>
      
</EventTrigger.Actions>
         
</EventTrigger>

    
</Style.Triggers>
 
</Style>
</Page.Resources>
  
<StackPanel Margin="20">

    
    
<Rectangle Name="MyRectangle" Width="100" Height="100" Style="{StaticResource oStyle}"/>
  
</StackPanel>
</Page>