Question

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.

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?

Was it helpful?

Solution

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.

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top