<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
程式碼如下
一、建立EdgeLight.xaml程式碼如下。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:WPFDevelopers.Controls"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Basic/ControlBasic.xaml"/> </ResourceDictionary.MergedDictionaries> <Style TargetType="{x:Type controls:EdgeLight}" BasedOn="{StaticResource ControlBasicStyle}"> <Setter Property="BorderBrush" Value="{DynamicResource PrimaryNormalSolidColorBrush}"/> <Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="HorizontalAlignment" Value="Center"/> <Setter Property="VerticalAlignment" Value="Center"/> <Setter Property="Padding" Value="20"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type controls:EdgeLight}"> <ControlTemplate.Resources> <Storyboard x:Key="EdgeLightStoryboard"> <DoubleAnimation Duration="00:00:0.5" To="1" Storyboard.TargetName="PART_Top" Storyboard.TargetProperty="ScaleX"/> <DoubleAnimation Duration="00:00:0.5" BeginTime="00:00:0.5" To="1" Storyboard.TargetName="PART_Right" Storyboard.TargetProperty="ScaleY"/> <DoubleAnimation Duration="00:00:.5" BeginTime="00:00:01" To="1" Storyboard.TargetName="PART_Bottom" Storyboard.TargetProperty="ScaleX"/> <DoubleAnimation Duration="00:00:.5" BeginTime="00:00:01.5" To="1" Storyboard.TargetName="PART_Left" Storyboard.TargetProperty="ScaleY"/> </Storyboard> </ControlTemplate.Resources> <Grid> <DockPanel LastChildFill="False"> <Rectangle DockPanel.Dock="Top" Height="{TemplateBinding LineSize}" Fill="{TemplateBinding BorderBrush}"> <Rectangle.RenderTransform> <ScaleTransform x:Name="PART_Top" ScaleX="0"/> </Rectangle.RenderTransform> </Rectangle> <Rectangle DockPanel.Dock="Right" Width="{TemplateBinding LineSize}" Fill="{TemplateBinding BorderBrush}"> <Rectangle.RenderTransform> <ScaleTransform x:Name="PART_Right" ScaleY="0"/> </Rectangle.RenderTransform> </Rectangle> <Rectangle DockPanel.Dock="Bottom" Height="{TemplateBinding LineSize}" Fill="{TemplateBinding BorderBrush}" RenderTransformOrigin="1,1"> <Rectangle.RenderTransform> <ScaleTransform x:Name="PART_Bottom" ScaleX="0"/> </Rectangle.RenderTransform> </Rectangle> <Rectangle DockPanel.Dock="Left" Width="{TemplateBinding LineSize}" Fill="{TemplateBinding BorderBrush}" RenderTransformOrigin="1,1"> <Rectangle.RenderTransform> <ScaleTransform x:Name="PART_Left" ScaleY="0"/> </Rectangle.RenderTransform> </Rectangle> </DockPanel> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsAnimation" Value="True"> <Trigger.EnterActions> <BeginStoryboard x:Name="beginAnimation" Storyboard="{StaticResource EdgeLightStoryboard}" /> </Trigger.EnterActions> <Trigger.ExitActions> <StopStoryboard BeginStoryboardName="beginAnimation" /> </Trigger.ExitActions> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary>
二、EdgeLight.cs程式碼如下。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Animation; namespace WPFDevelopers.Controls { public class EdgeLight:ContentControl { public bool IsAnimation { get { return (bool)GetValue(IsAnimationProperty); } set { SetValue(IsAnimationProperty, value); } } public static readonly DependencyProperty IsAnimationProperty = DependencyProperty.Register("IsAnimation", typeof(bool), typeof(EdgeLight), new PropertyMetadata(false)); public double LineSize { get { return (double)GetValue(LineSizeProperty); } set { SetValue(LineSizeProperty, value); } } public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register("LineSize", typeof(double), typeof(EdgeLight), new PropertyMetadata(1.0d)); static EdgeLight() { DefaultStyleKeyProperty.OverrideMetadata(typeof(EdgeLight), new FrameworkPropertyMetadata(typeof(EdgeLight))); } } }
三、新建EdgeLightExample.cs程式碼如下。
<UserControl x:Class="WPFDevelopers.Samples.ExampleViews.EdgeLightExample" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:WPFDevelopers.Samples.ExampleViews" xmlns:wpfdev="https://github.com/yanjinhuagood/WPFDevelopers" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> <Grid> <UniformGrid Columns="2"> <wpfdev:EdgeLight IsAnimation="{Binding ElementName=myCheckBox,Path=IsChecked}" Margin="10" LineSize="2"> <CheckBox Content="EdgeLight" x:Name="myCheckBox"/> </wpfdev:EdgeLight> <wpfdev:EdgeLight IsAnimation="{Binding ElementName=myToggleButton,Path=IsChecked}" Margin="10" BorderBrush="OrangeRed" LineSize="4"> <ToggleButton Content="EdgeLight2" x:Name="myToggleButton"/> </wpfdev:EdgeLight> </UniformGrid> </Grid> </UserControl>
效果預覽
到此這篇關於基於WPF實現控制元件輪廓跑馬燈動畫效果的文章就介紹到這了,更多相關WPF跑馬燈動畫內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45