大家好,欢迎来到IT知识分享网。
最近微软亚洲研究院的人立方关系搜索新发布了几个Silverlight的应用,包括关系图搜索,六度搜索和新闻时间轴。相信其绚丽的界面效果和赏心悦目的动画给大家留下了深刻印象。这里,我就尝试和大家一起来对这些应用进行揭谜,着重探讨siliverlight中三种定制控件外观的方法: 1) 这种方法只能对控件的外观做一些简单的,轻量级的修改。比如这个半透明的矩形框: 我们只需要在代码里面这样写: <Rectangle Fill=”White” Opacity=”0.1″ Height=”75″ Canvas.Left=”0″ Canvas.Top=”1″ Margin=”0,0,0,100″ Width=”20000″/> 其中Opacity属性就是设置矩形框的透明度,这里设为0.1,使其非常透明。可惜的是,这个矩形框在后来的设计中去掉了L 2) 很多情况下,上面的方法就够用了。但是有时我们会遇到这样的情况:我们需要给多个控件设置类似的属性。仍然以上面的矩形框为例子,那代码就会是这样: <Rectangle Fill=”White” Opacity=”0.1″ Height=”75″ Canvas.Left=”0″ Canvas.Top=”1″ Margin=”0,0,0,100″ Width=”2000″/> <Rectangle Fill=”White” Opacity=”0.2″ Height=”75″ Canvas.Left=”0″ Canvas.Top=”1″ Margin=”0,0,0,100″ Width=”2000″/> <Rectangle Fill=”White” Opacity=”0.3″ Height=”75″ Canvas.Left=”0″ Canvas.Top=”1″ Margin=”0,0,0,100″ Width=”2000″/> <Rectangle Fill=”White” Opacity=”0.4″ Height=”75″ Canvas.Left=”0″ Canvas.Top=”1″ Margin=”0,0,0,100″ Width=”2000″/> ……
我们仍然以六度搜索界面中的控件为例子: 图中白色的矩形框显示了两个人物之间的关系来源。 <TextBlock x:Name=”textBlock” Text=”{Binding Path=TitleB}” Style=”{StaticResource 这个TextBlock的风格指向了名为”TitleBlock”的资源,其定义为: <Style x:Key=”TitleBlock” TargetType=”TextBlock”> <Setter Property=”FontFamily” Value=”Microsoft YaHei”/> <Setter Property=”FontSize” Value=”12″/> <Setter Property=”VerticalAlignment” Value=”Center”/> <Setter Property=”HorizontalAlignment” Value=”Left”/> <Setter Property=”Grid.Row” Value=”1″/> <Setter Property=”Grid.Column” Value=”1″/> <Setter Property=”Grid.ColumnSpan” Value=”1″/> </Style> 这样,多个控件可以共享这个名为“TitleBlock”的资源。我们可以通过修改这个资源文件,从而轻易的修改多个控件的外观。 3) 有时我们不得不面对复杂一些的情况: 请看图中黄色椭圆框中的控件,它们都是Button控件,但是其外观被完全改头换面了。我会选取其中三个控件作为例子在这里谈一谈: 3.1 这个按钮的外形是个三角形,其定义为: <Button x:Name=”arrowUp” Canvas.Top=”9″ Canvas.Left=”15″ Canvas.ZIndex=”99″ Style=”{StaticResource ArrowUpButton}”Click=”ArrayUp_Click”/>
<Style x:Key=”ArrowUpButton” TargetType=”Button”>
<Setter Property=”Template”> <Setter.Value> <ControlTemplate TargetType=”Button”>
我们可以看到,这个控件的“内部”被放入了一个Polygon控件,所以这个箭头按钮会呈现这个Polygon所描绘的三角形。 3.2 那么如果想做这个具有人立方特色的圆圈按钮,其步骤就可以分为如下几步: 3.2.1 <Grid Height=”auto” HorizontalAlignment=”Center” VerticalAlignment=”Center” Width=”auto” IsHitTestVisible=”True”Background=”{x:Null}”> <Ellipse Margin=”0,0,0,0″ Stroke=”{x:Null}” HorizontalAlignment=”Center” VerticalAlignment=”Center” Width=”{TemplateBindingCircleButtonWidth1}” Height=”{TemplateBinding CircleButtonHeight1}” IsHitTestVisible=”False” x:Name=”ellipse1″Fill=”{TemplateBinding Ellipse1Fill}”> </Ellipse> <Grid Margin=”0,0,0,0″ HorizontalAlignment=”Center” Width=”1024″ Height=”1024″ VerticalAlignment=”Center”RenderTransformOrigin=”0.5,0.5″ x:Name=”grid” Opacity=”1″ Background=”{x:Null}” IsHitTestVisible=”True”> <Ellipse Fill=”{TemplateBinding Ellipse2Fill}” Stroke=”{TemplateBinding Ellipse2Stroke}” Margin=”0,0,0,0″ Width=”{TemplateBindingCircleButtonWidth2}” Height=”{TemplateBinding CircleButtonHeight2}” x:Name=”ellipse2″ RenderTransformOrigin=”0.5,0.5″HorizontalAlignment=”Center” VerticalAlignment=”Center”> </Ellipse> <Ellipse Margin=”2,2,2,2″ Fill=”{TemplateBinding Ellipse3Fill}” Width=”{TemplateBinding CircleButtonWidth3}”Height=”{TemplateBinding CircleButtonHeight3}” x:Name=”ellipse3″ RenderTransformOrigin=”0.5,0.5″ HorizontalAlignment=”Center”VerticalAlignment=”Center”> </Ellipse> <TextBlock Margin=”0,0,0,0″ FontFamily=”Microsoft YaHei” FontSize=”{TemplateBinding FontSize}” Foreground=”#FFFFFFFF”HorizontalAlignment=”Center” VerticalAlignment=”Center” x:Name=”textBlock” Text=”{TemplateBinding Content}”RenderTransformOrigin=”0.5,0.5″ IsHitTestVisible=”False”> </TextBlock> </Grid> </Grid> 3.2.2 /// /// The ellipse1 fill. /// public Brush Ellipse1Fill { get { return (Brush)base.GetValue(Ellipse1FillProperty); } set { base.SetValue(Ellipse1FillProperty, value); } } /// /// Register property. /// public static readonly DependencyProperty Ellipse1FillProperty = DependencyProperty.Register(“Ellipse1Fill”, typeof(Brush),typeof(CircleButton), null); 这里我们就注册了名为Ellipse1Fill的属性,于是就可以设置它的值: 3.2.3 <VisualState x:Name=”MouseOver”> <Storyboard> <DoubleAnimationUsingKeyFrames BeginTime=”00:00:00″ Duration=”00:00:00.0010000″ Storyboard.TargetName=”ellipse2″Storyboard.TargetProperty=”(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)”> <SplineDoubleKeyFrame KeyTime=”00:00:00″ Value=”1.5″/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames BeginTime=”00:00:00″ Duration=”00:00:00.0010000″ Storyboard.TargetName=”ellipse2″Storyboard.TargetProperty=”(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)”> <SplineDoubleKeyFrame KeyTime=”00:00:00″ Value=”1.5″/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames BeginTime=”00:00:00″ Duration=”00:00:00.0010000″ Storyboard.TargetName=”ellipse3″Storyboard.TargetProperty=”(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)”> <SplineDoubleKeyFrame KeyTime=”00:00:00″ Value=”1.5″/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames BeginTime=”00:00:00″ Duration=”00:00:00.0010000″ Storyboard.TargetName=”ellipse3″Storyboard.TargetProperty=”(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)”> <SplineDoubleKeyFrame KeyTime=”00:00:00″ Value=”1.5″/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames BeginTime=”00:00:00″ Duration=”00:00:00.0010000″ Storyboard.TargetName=”textBlock”Storyboard.TargetProperty=”(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)”> <SplineDoubleKeyFrame KeyTime=”00:00:00″ Value=”1.5″/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames BeginTime=”00:00:00″ Duration=”00:00:00.0010000″ Storyboard.TargetName=”textBlock”Storyboard.TargetProperty=”(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)”> <SplineDoubleKeyFrame KeyTime=”00:00:00″ Value=”1.5″/> </DoubleAnimationUsingKeyFrames> </Storyboard> </VisualState> 这样,这个具有人立方特色的圆圈按钮就完成了。 3.3 线段按钮 人立方的silverlight应用里面还有这样的线段按钮,它很细,但是很容易被鼠标点击到,具有很好的用户体验。其制作步骤也是类似的: 3.3.1. a) <Path x:Name=”outerPath” Stroke=”White” StrokeThickness=”10″ Data=”{TemplateBinding OuterPathData}” Opacity=”0″></Path> b) <Path x:Name=”path” Stroke=”White” StrokeThickness=”1″ Data=”{TemplateBinding PathData}” Opacity=”{TemplateBindingOpacity}”></Path> 3.3.2. public Geometry PathData public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(“PathData”, typeof(Geometry),typeof(PathButton), null);
3.3.3. this.PathData = CreatePathData();
3.3.4. DoubleAnimation opacity = new DoubleAnimation(); opacity.From = 0; opacity.To = endOpacity; opacity.Duration = new Duration(TimeSpan.FromSeconds(1)); Storyboard story = new Storyboard(); story.Children.Add(opacity); Storyboard.SetTarget(opacity, this); Storyboard.SetTargetProperty(opacity, new PropertyPath(“(UIElement.Opacity)”)); story.BeginTime = TimeSpan.FromSeconds(beginTime); story.Completed += new EventHandler(AppearStory_Completed); story.Begin(); 使得当鼠标hover到线段按钮上时,整条线段变亮。
转:Windows Live中文社区http://forum.livetome.cn/thread-11738-1-1.html
快速链接: 人立方实时资讯关系图(Flash):http://renlifang.msra.cn/newsMap.aspx |
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/32900.html