【问题标题】:Animating WindowsFormsHost动画 WindowsFormsHost
【发布时间】:2012-07-18 13:15:04
【问题描述】:

我需要为 WindowsFormsHost 控件设置动画。问题是我看不到动画,窗口没有刷新。如果我在动画期间调整 WPF 窗口的大小,则过渡可见。

我尝试将 WindowsFormsHost 放在网格中,然后为网格设置动画,但结果是一样的。我在网格中添加了一些其他的东西,以确保我正确地编写了动画。

这里有一些简单的应用程序来测试这个:

<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>

有什么办法可以解决吗?

【问题讨论】:

    标签: c# wpf animation windowsformshost


    【解决方案1】:

    在混合 WPF 和 WinForms 或 ActiveX 内容时,这是一个已知问题。在内部,每个渲染引擎都有自己的空域,无法正常实现动画等互操作性。

    随着 .net 4.5 版本的发布,这个问题应该得到解决。

    http://www.jonathanantoine.com/2011/09/24/wpf-4-5-%E2%80%93-part-8-no-more-airspace-problems-integrating-wpf-with-win32/

    【讨论】:

    • 这太糟糕了。谁能确认一下?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-21
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    • 1970-01-01
    相关资源
    最近更新 更多