第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

WPF 雙動畫無法正常工作 C#

WPF 雙動畫無法正常工作 C#

C#
BIG陽 2021-07-03 09:41:32
當(dāng)我嘗試為我的主窗口設(shè)置動畫時,只有 Height 正在設(shè)置動畫,但是當(dāng)我使用相同的代碼為我的網(wǎng)格設(shè)置動畫時,它工作正常。請幫助我,因?yàn)槲沂?wpf 的新手<Window x:Class="TestingDemo.MainWindow"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    xmlns:local="clr-namespace:TestingDemo"    mc:Ignorable="d"    Name="myWindow"    AllowsTransparency="True"    WindowStyle="None"    Background="Blue"    Title="MainWindow" Height="100" Width="100"><Grid>    <TextBlock MouseDown="TextBlock_MouseDown">        OpenMe        <TextBlock.Triggers>            <EventTrigger RoutedEvent="MouseDown">                <BeginStoryboard>                    <Storyboard>                        <DoubleAnimation                            Storyboard.TargetName="myWindow"                            Storyboard.TargetProperty="Height"                            From="100"                            To="600"></DoubleAnimation>                        <DoubleAnimation                            Storyboard.TargetName="myWindow"                            Storyboard.TargetProperty="Width"                            From="100"                            To="600"></DoubleAnimation>                    </Storyboard>                </BeginStoryboard>            </EventTrigger>        </TextBlock.Triggers>    </TextBlock>   </Grid></Window>寬
查看完整描述

2 回答

?
慕田峪9158850

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超7個贊

遺憾的是,更改Width和Height的Window分離且昂貴。該Width和Height的Window是WPF依賴屬性,但他們在本機(jī)的方式工作。的相同屬性Grid以 WPF 方式工作。


建議避免為 的Width和Height屬性設(shè)置動畫Window。相反,動畫內(nèi)部框架元素。


我已經(jīng)嘗試過下面的代碼,但它運(yùn)行不流暢:


while (true)

{

    await Task.Delay(10);

    Width += 10;

    Height += 10;

}


查看完整回答
反對 回復(fù) 2021-07-10
?
慕運(yùn)維8079593

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個贊

這是我正在做的事情,它就像一個魅力:


  <Window.Triggers>

        <EventTrigger RoutedEvent="Loaded">

            <BeginStoryboard>

                <Storyboard>

                    <DoubleAnimation Storyboard.TargetProperty="Width" From="0" To="yourWidth" Duration="0:0:1" FillBehavior="HoldEnd" AutoReverse="False" />

                    <DoubleAnimation Storyboard.TargetProperty="Height" From="0" To="yourHeight" Duration="0:0:3" FillBehavior="HoldEnd" AutoReverse="False"/>

                </Storyboard>

            </BeginStoryboard>

        </EventTrigger>

 </Window.Triggers>


    I have hooked it for Window Loaded event but you can change it as you wish but the key is If you want smooth animation then you have to manually push frames in a timer or thread like:


  /// <summary>

    /// 

    /// </summary>

    public static class DispatcherHelper

    {

        /// <summary>

        /// Simulate Application.DoEvents function of <see cref=" System.Windows.Forms.Application"/> class.

        /// </summary>

        [SecurityPermissionAttribute ( SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode )]

        public static void DoEvents ( )

        {

            DispatcherFrame frame = new DispatcherFrame ( );

            Dispatcher.CurrentDispatcher.BeginInvoke ( DispatcherPriority.Background,

                new DispatcherOperationCallback ( ExitFrames ), frame );


            try

            {

                Dispatcher.PushFrame ( frame );

            }

            catch ( InvalidOperationException )

            {

            }

        }

        /// <summary>

        /// 

        /// </summary>

        /// <param name="f"></param>

        /// <returns></returns>

        private static object ExitFrames ( object frame )

        {

            ( ( DispatcherFrame ) frame ).Continue = false;


            return null;

        }

    }

請小心,因?yàn)椴唤ㄗh手動推送幀,但如果您知道自己在做什么,那么請自重!:)。


查看完整回答
反對 回復(fù) 2021-07-10
  • 2 回答
  • 0 關(guān)注
  • 167 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號