最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

WPF實(shí)現(xiàn)3D翻牌式倒計(jì)時(shí)特效

 更新時(shí)間:2020年09月02日 08:44:38   作者:RunnerDNA  
這篇文章主要為大家詳細(xì)介紹了WPF實(shí)現(xiàn)3D翻牌式倒計(jì)時(shí)特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了WPF實(shí)現(xiàn)3D翻牌式倒計(jì)時(shí)的具體代碼,供大家參考,具體內(nèi)容如下

實(shí)現(xiàn)效果如下:

思路:使用自定義控件,設(shè)置一個(gè)背板 MyCardControlBottom,一個(gè)卡牌翻動(dòng)的前部 MyCardControlFront,一個(gè)卡牌翻動(dòng)后的背部 MyCardControlBack,另外實(shí)現(xiàn)卡牌翻動(dòng)的MyCardControl;在主窗體中設(shè)置一計(jì)時(shí)器,根據(jù)卡牌上的數(shù)字和計(jì)時(shí)器時(shí)間啟動(dòng)翻牌動(dòng)作。

主要代碼:

1、自定義控件MyCardControlBottom

<UserControl x:Class="TurnOverCards.MyCardControlBottom"
    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" 
    x:Name="MyUserControl"
    Height="300" Width="200">
 <Border BorderThickness="0">
  <Border.Effect>
   <DropShadowEffect BlurRadius="20" Color="Gray" Direction="-90" ShadowDepth="10"></DropShadowEffect>
  </Border.Effect>
  <Border.Background>
   <RadialGradientBrush GradientOrigin="0.5,0.5" Center="0.5,0.5" RadiusX="0.75" RadiusY="0.65">
    <GradientStop Color="DimGray" Offset="0" />
    <GradientStop Color="Black" Offset="1" />
   </RadialGradientBrush>
  </Border.Background>
  <Grid>
   <Grid.RowDefinitions>
    <RowDefinition></RowDefinition>
    <RowDefinition></RowDefinition>
   </Grid.RowDefinitions>
   <TextBlock Grid.Row="0" Text="{Binding ElementName=MyUserControl,Path=BottomText}" FontFamily="Arial" Foreground="White" FontSize="150" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,65,0,2">
    <TextBlock.Effect>
     <DropShadowEffect BlurRadius="10" Color="Black" Direction="-90" ShadowDepth="2"></DropShadowEffect>
    </TextBlock.Effect>
   </TextBlock>
   <TextBlock Grid.Row="1" Text="{Binding ElementName=MyUserControl,Path=BottomText}" FontFamily="Arial" Foreground="White" FontSize="150" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,65">
    <TextBlock.Effect>
     <DropShadowEffect BlurRadius="10" Color="Black" Direction="-90" ShadowDepth="2"></DropShadowEffect>
    </TextBlock.Effect>
   </TextBlock>
  </Grid>
 </Border>
</UserControl>

其中BottomText為自定義屬性。

public static readonly DependencyProperty BottomTextProperty = DependencyProperty.Register("BottomText", typeof(string), typeof(MyCardControlBottom), new PropertyMetadata(null));
  public string BottomText
  {
   get { return (string)GetValue(BottomTextProperty); }
   set { SetValue(BottomTextProperty, value); }
  }

2、自定義控件MyCardControlFront

<UserControl x:Class="TurnOverCards.MyCardControlFront"
    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" 
    x:Name="MyUserControl"
    Height="150" Width="200">
 <Border BorderThickness="0" ClipToBounds="True">
  <Border.Background>
   <RadialGradientBrush GradientOrigin="0.5,0.75" Center="0.5,0.5" RadiusX="0.75" RadiusY="0.75">
    <GradientStop Color="DimGray" Offset="0" />
    <GradientStop Color="Black" Offset="1" />
   </RadialGradientBrush>
  </Border.Background>
  <TextBlock Text="{Binding ElementName=MyUserControl,Path=FrontText}" FontFamily="Arial" Foreground="White" FontSize="150" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,65,0,2">
   <TextBlock.Effect>
    <DropShadowEffect BlurRadius="10" Color="Black" Direction="-90" ShadowDepth="2"></DropShadowEffect>
   </TextBlock.Effect>
  </TextBlock>
 </Border>
</UserControl>

其中FrontText為自定義屬性。

3、自定義控件MyCardControlBack

窗體大部分布局與MyCardControlFront 相同,字體部分需要進(jìn)行翻轉(zhuǎn)顯示,其中BackText為自定義屬性。

<TextBlock Text="{Binding ElementName=MyUserControl,Path=BackText}" FontFamily="Arial" Foreground="White" FontSize="150" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,-85"
     RenderTransformOrigin="0.5,0.5">
   <TextBlock.Effect>
    <DropShadowEffect BlurRadius="10" Color="Black" Direction="-90" ShadowDepth="2"></DropShadowEffect>
   </TextBlock.Effect>
   <TextBlock.RenderTransform >
    <ScaleTransform ScaleX="-1" ScaleY="-1"/>
   </TextBlock.RenderTransform>
</TextBlock>

4、自定義控件MyCardControl

卡牌翻轉(zhuǎn)動(dòng)作在這里實(shí)現(xiàn)。

<UserControl x:Class="TurnOverCards.MyCardControl"
    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:TurnOverCards"
    x:Name="UserControl"
    Loaded="MyUserControl_Loaded">
 <Viewport3D Width="200" Height="300">
  <Viewport3D.Camera>
   <PerspectiveCamera Position="0 -150 480" LookDirection="0 0 -1"/>
  </Viewport3D.Camera>
  <Viewport3D.Children>
   <ModelVisual3D>
    <ModelVisual3D.Content>
     <DirectionalLight Color="Transparent"/>
    </ModelVisual3D.Content>
   </ModelVisual3D>
   <ContainerUIElement3D>
    <Viewport2DVisual3D>
     <Viewport2DVisual3D.Geometry>
      <MeshGeometry3D Positions="-200 150 0 -200 -150 0 200 -150 0 200 150 0" TriangleIndices="0 1 2 0 2 3" TextureCoordinates="0 0 0 1 1 1 1 0"/>
     </Viewport2DVisual3D.Geometry>
     <Viewport2DVisual3D.Material>
      <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
     </Viewport2DVisual3D.Material>
     <Viewport2DVisual3D.Visual>
      <local:MyCardControlFront x:Name="frontControl" Width="200" Height="150"/>
     </Viewport2DVisual3D.Visual>
    </Viewport2DVisual3D>
    <Viewport2DVisual3D>
     <Viewport2DVisual3D.Geometry>
      <MeshGeometry3D Positions="200 150 0 200 -150 0 -200 -150 0 -200 150 0" TriangleIndices="0 1 2 0 2 3" TextureCoordinates="0 0 0 1 1 1 1 0"/>
     </Viewport2DVisual3D.Geometry>
     <Viewport2DVisual3D.Material>
      <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
     </Viewport2DVisual3D.Material>
     <Viewport2DVisual3D.Visual>
      <local:MyCardControlBack x:Name="backControl" Width="200" Height="150"/>
     </Viewport2DVisual3D.Visual>
    </Viewport2DVisual3D>
    <ContainerUIElement3D.Transform>
     <Transform3DGroup>
      <RotateTransform3D CenterX="0" CenterY="-150" CenterZ="0">
       <RotateTransform3D.Rotation>
        <AxisAngleRotation3D x:Name="MyAxisAngleRotation3D" Angle="0" Axis="1 0 0"/>
       </RotateTransform3D.Rotation>
      </RotateTransform3D>
     </Transform3DGroup>
    </ContainerUIElement3D.Transform>
   </ContainerUIElement3D>
  </Viewport3D.Children>
 </Viewport3D>
</UserControl>

加載時(shí)賦值:

public int ShowValue { get; set; }  
  
  private void MyUserControl_Loaded(object sender, RoutedEventArgs e)
  {
   this.frontControl.FrontText = ShowValue.ToString();
  }

5、主窗體交互邏輯

private int Count = 10;
private DispatcherTimer frameTimer;
private int TimeValue = 0;
 
  private void Window_Loaded(object sender, RoutedEventArgs e)
  {
   this.bottomControl.BottomText = Count.ToString();
 
   for (int i = 1; i <= Count; i++)
   {
    var card = new MyCardControl();
    card.ShowValue = i;
    this.mainGrid.Children.Add(card);
    Canvas.SetZIndex(card, i);
   }
 
   frameTimer = new DispatcherTimer();
   frameTimer.Tick += OnFrame;
   frameTimer.Interval = TimeSpan.FromSeconds(1);
   frameTimer.Start();
  }
 
  private void OnFrame(object sender, EventArgs e)
  {
   if (TimeValue >= Count)
   {
    if (frameTimer != null)
     frameTimer.Stop();
    return;
   }
 
   if(TimeValue == Count - 1)
   {
    this.bottomControl.BottomText = 0.ToString();
   }
 
   List<MyCardControl> cardList = GetChildObjects<MyCardControl>(this.mainGrid);
   foreach (var item in cardList)
   {
    if(item.ShowValue == Count - TimeValue)
    {
     Canvas.SetZIndex(item, Count + TimeValue);
 
     DoubleAnimation da = new DoubleAnimation();
     da.Duration = new Duration(TimeSpan.FromSeconds(1));
     da.To = 180d;
     item.ShowValue--;
     item.backControl.BackText = item.ShowValue.ToString();
     
     AxisAngleRotation3D aar = item.FindName("MyAxisAngleRotation3D") as AxisAngleRotation3D;
     if (aar != null)
      aar.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);
     
     break;
    }
   }
 
   TimeValue++;
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C#使用AngleSharp庫解析html文檔

    C#使用AngleSharp庫解析html文檔

    這篇文章介紹了C#使用AngleSharp庫解析html文檔的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-06-06
  • C#及WPF獲取本機(jī)所有字體和顏色的方法

    C#及WPF獲取本機(jī)所有字體和顏色的方法

    這篇文章主要介紹了C#及WPF獲取本機(jī)所有字體和顏色的方法,實(shí)例分析了C#及WPF獲取本機(jī)字體及顏色的相關(guān)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下
    2015-09-09
  • C# Entity Framework中的IQueryable和IQueryProvider詳解

    C# Entity Framework中的IQueryable和IQueryProvider詳解

    這篇文章主要介紹了C# Entity Framework中的IQueryable和IQueryProvider詳解,本文使用實(shí)例分析這兩個(gè)接口的內(nèi)部實(shí)現(xiàn),需要的朋友可以參考下
    2015-01-01
  • C#?將數(shù)據(jù)庫SqlServer數(shù)據(jù)綁定到類中的過程詳解

    C#?將數(shù)據(jù)庫SqlServer數(shù)據(jù)綁定到類中的過程詳解

    本文講述的是讀取數(shù)據(jù)庫中數(shù)據(jù)的常用做法,即將數(shù)據(jù)庫中的數(shù)據(jù)綁定到創(chuàng)建的類中,再將類綁定到DataGridView的數(shù)據(jù)源中的做法,對(duì)C#將SqlServer數(shù)據(jù)綁定到類中感興趣的朋友一起看看吧
    2022-06-06
  • C#面向?qū)ο缶幊讨氯螒驅(qū)崿F(xiàn)方法

    C#面向?qū)ο缶幊讨氯螒驅(qū)崿F(xiàn)方法

    這篇文章主要介紹了C#面向?qū)ο缶幊讨氯螒驅(qū)崿F(xiàn)方法,以一個(gè)完整的猜拳游戲?yàn)槔v述了C#面向?qū)ο蟪绦蛟O(shè)計(jì)的具體實(shí)現(xiàn)步驟,具有一定的學(xué)習(xí)與借鑒價(jià)值,需要的朋友可以參考下
    2014-11-11
  • C#?WPF編程之元素綁定詳解

    C#?WPF編程之元素綁定詳解

    數(shù)據(jù)綁定是一種關(guān)系,該關(guān)系告訴WPF從源對(duì)象提取一下信息,并用這些信息設(shè)置目標(biāo)對(duì)象的屬性,下面我們就來了解一下WPF編程中元素綁定的相關(guān)知識(shí)吧
    2024-04-04
  • C# SESSION丟失問題的解決辦法

    C# SESSION丟失問題的解決辦法

    這篇文章主要為大家詳細(xì)介紹了C# SESSION丟失問題的解決辦法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • C#實(shí)現(xiàn)數(shù)組元素的數(shù)據(jù)類型轉(zhuǎn)換方法詳解

    C#實(shí)現(xiàn)數(shù)組元素的數(shù)據(jù)類型轉(zhuǎn)換方法詳解

    這篇文章主要為大家介紹了C#中一維數(shù)組如何快速實(shí)現(xiàn)數(shù)組元素的數(shù)據(jù)類型的轉(zhuǎn)換,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下
    2022-04-04
  • C#圖像處理的多種方法

    C#圖像處理的多種方法

    這篇文章主要為大家詳細(xì)介紹了C#圖像處理的多種方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-09-09
  • C# DataTable.Select()根據(jù)條件篩選數(shù)據(jù)問題

    C# DataTable.Select()根據(jù)條件篩選數(shù)據(jù)問題

    這篇文章主要介紹了C# DataTable.Select()根據(jù)條件篩選數(shù)據(jù)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01

最新評(píng)論

凤城市| 侯马市| 台中市| 和田市| 左贡县| 姚安县| 南江县| 昌平区| 申扎县| 咸丰县| 扎兰屯市| 启东市| 廊坊市| 德钦县| 荃湾区| 沿河| 大新县| 项城市| 高雄市| 门头沟区| 江源县| 吉首市| 尼木县| 葵青区| 上犹县| 社旗县| 汝城县| 金堂县| 祥云县| 临沭县| 达拉特旗| 松潘县| 黄石市| 湘阴县| 钟山县| 稻城县| 电白县| 乌兰察布市| 同心县| 壤塘县| 吉隆县|