91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

基于WPF如何實現控件輪廓跑馬燈動畫效果

發布時間:2022-08-08 17:39:28 來源:億速云 閱讀:240 作者:iii 欄目:開發技術

這篇文章主要講解了“基于WPF如何實現控件輪廓跑馬燈動畫效果”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“基于WPF如何實現控件輪廓跑馬燈動畫效果”吧!

代碼如下

一、創建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如何實現控件輪廓跑馬燈動畫效果”的內容了,經過本文的學習后,相信大家對基于WPF如何實現控件輪廓跑馬燈動畫效果這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

wpf
AI

中阳县| 个旧市| 钟祥市| 垣曲县| 定边县| 丹阳市| 乌拉特中旗| 黄浦区| 东丰县| 六安市| 南陵县| 北京市| 本溪市| 嘉荫县| 五家渠市| 佳木斯市| 璧山县| 旌德县| 屏边| 迁安市| 岗巴县| 石河子市| 墨脱县| 岳阳市| 会同县| 毕节市| 东兰县| 石嘴山市| 修水县| 武川县| 商水县| 宁波市| 平湖市| 大兴区| 天峨县| 黑河市| 紫阳县| 吉水县| 织金县| 洪洞县| 湖南省|