在wpf中创建WindowsFormHost的反射

3

我对WPF非常陌生并且卡住了。

我正在尝试创建一个演示程序,显示几个嵌入式win表单应用程序。我想添加表单的反射,但大多数现有的图像反射教程都不起作用。

如果有人能指点我正确的方向,我会非常感激。

这是相关的XAML - 表单控件被动态地添加到 embedForm 堆栈面板中。

        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Border Name="inkBorder" Grid.Row="0" VerticalAlignment="Bottom" Margin="20"
            Width="400" Height="500" CornerRadius="5" BorderThickness="4">
                <Border.BorderBrush>
                    <LinearGradientBrush SpreadMethod="Reflect" StartPoint="0,0" EndPoint="0.5,0.5">
                        <LinearGradientBrush.GradientStops>
                            <GradientStop Color="Gray" Offset="0" />
                            <GradientStop Color="#eeeeee" Offset="1" />
                        </LinearGradientBrush.GradientStops>
                    </LinearGradientBrush>
                </Border.BorderBrush>
            <StackPanel Name="EmbedForm" Height="100" Width="400" ></StackPanel>
        </Border>

            <Rectangle Grid.Row="1" VerticalAlignment="Top"
               Width="{Binding ElementName=inkBorder,Path=ActualWidth}"
               Height="{Binding ElementName=inkBorder,Path=ActualHeight}">

                <Rectangle.OpacityMask>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                        <LinearGradientBrush.GradientStops>
                            <GradientStop Offset="0.0" Color="#66000000" />
                            <GradientStop Offset="1.0" Color="#00000000" />
                        </LinearGradientBrush.GradientStops>
                    </LinearGradientBrush>
                </Rectangle.OpacityMask>
                <Rectangle.Fill>
                    <VisualBrush 
          Visual="{Binding ElementName=inkBorder}">
                        <VisualBrush.RelativeTransform>
                            <TransformGroup>
                                <ScaleTransform ScaleX="1" ScaleY="-1" />
                                <TranslateTransform Y="1" />
                            </TransformGroup>
                        </VisualBrush.RelativeTransform>
                    </VisualBrush>
                </Rectangle.Fill>
            </Rectangle>
        </Grid>

为了更清晰地阐明这个问题...

我主要是在寻找一种方法,可以将任何的视觉变换应用于像 WindowsFormHostWebBrowser 这样的控件。

我发现即使是简单的变换对于这些控件也不起作用,所以我想知道是否有什么技巧可以将它们视为标准的可视元素或者这是一个无解的问题。

1个回答

3

WindowsFormsHostWebBrowser上的变换不起作用,因为这些控件不使用WPF渲染引擎,而是使用GDI+。

据我所知,实现您想要的唯一方法是将控件内容捕获为图像,并使用GDI+函数手动对图像执行变换... 对于简单的反射来说,这很容易,但对于其他类型的变换可能会有些棘手...


谢谢 - 这正是我需要知道的 - 如果可以问一下,您是否有捕获图像资源的链接?我的搜索结果非常不理想。非常感谢您的帮助。 - Kelly Robins
1
请查看此链接:http://www.developerfusion.com/code/4630/capture-a-screen-shot/。它也适用于控件(因为Win32控件具有窗口句柄)。 - Thomas Levesque
非常感谢!很抱歉这样增加了问题。 - Kelly Robins

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接