[英]Animating WindowsFormsHost
我需要设置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>
有什么办法可以解决这个问题?
混合WPF和WinForms或ActiveX内容时,这是一个已知问题。 每个渲染引擎在内部都有自己的领空,无法像动画一样实现互操作性。
使用.net 4.5版本时,应解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.