代码之家  ›  专栏  ›  技术社区  ›  Kelly Robins

在WPF中创建WindowsFormHost的反射

  •  3
  • Kelly Robins  · 技术社区  · 16 年前

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

    稍微澄清一下这个问题…

    我主要在寻找一种将任何可视化转换应用于控件的方法,比如 WindowsFormHost 以及 WebBrowser 控制。

    我发现,即使是简单的转换也不能用它们工作,我想知道是否有任何技巧可以像标准的视觉元素那样处理这些元素,或者它是一个失败的原因。

    1 回复  |  直到 11 年前
        1
  •  3
  •   Thomas Levesque    16 年前

    上的转换 WindowsFormsHost WebBrowser 不会工作,因为这些控件不使用WPF呈现引擎,所以它们使用gdi+。

    据我所知,实现所需功能的唯一方法是将控件的内容捕获为图像,并使用gdi+函数手动对图像执行转换…对于一个简单的反射来说是很容易的,但是对于其他类型的转换来说,它可能会变得很棘手…