本文介绍了动画WindowsFormsHost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要动画WindowsFormsHost控件。问题是,我看不到动画,窗口不刷新。如果我在动画过程中调整我的WPF窗口,然后过渡是可见的。

I need to animate WindowsFormsHost control. The problem is that I can't see the animation, the window doesn't refresh. If I resize my WPF window during the animation then the transition is visible.

我试图把WindowsFormsHost一个网格内,然后动画网格,但结果是一样的。我把一些其他的东西到电网,以确保我没有写的动画。

I tried putting WindowsFormsHost inside a grid and then animate the grid but the result is the same. I put some other stuff into the grid to make sure that I wrote the animation correctly.

下面是一些简单的应用程序只是为了测试这一点:

Here's some simple application just to test this:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
    Title="MainWindow" Height="350" Width="525">

<Window.Resources>
    <Grid x:Key="MoveX">
        <Grid.RenderTransform>
            <TranslateTransform X="0"/>
        </Grid.RenderTransform>
    </Grid>

    <Storyboard x:Key="Story">
        <DoubleAnimation
            Storyboard.Target="{StaticResource MoveX}"
            Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)"
            From="0"
            To="600"/>
    </Storyboard>
</Window.Resources>

<Grid>
    <Grid.RenderTransform>
        <TranslateTransform X="{Binding Source={StaticResource MoveX}, Path=RenderTransform.(TranslateTransform.X)}"/>
    </Grid.RenderTransform>

    <WindowsFormsHost Height="224" HorizontalAlignment="Left" Margin="26,24,0,0" Name="windowsFormsHost1" VerticalAlignment="Top" Width="404" Background="#FF762323">
        <wf:Panel BackColor="Green" Width="300" Height="200"/>
    </WindowsFormsHost>

    <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="328,269,0,0" Name="button1" VerticalAlignment="Top" Width="75" >
        <Button.Triggers>
            <EventTrigger RoutedEvent="Button.Click">
                <BeginStoryboard Storyboard="{StaticResource Story}"/>
            </EventTrigger>
        </Button.Triggers>
    </Button>
    <Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="85,269,0,0" Name="label1" VerticalAlignment="Top" />
</Grid>
</Window>

有没有办法解决呢?

Is there any way to fix that?

推荐答案

这混合WPF和WinForms或ActiveX内容时的一个已知问题。在内部每个渲染引擎都有自己的领空,如动画的互操作性是不可能正常。

That's a know issue when mixing WPF and WinForms or ActiveX content. Internally each render engine has its own airspace, interoperability like animations is not possible properly.

在.NET 4.5版本这个问题应该得到解决。

With the .net 4.5 release this issue should be solved.

请参阅

这篇关于动画WindowsFormsHost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:24