Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我是否可以将XAML/WPF窗口复制到第二个窗口中,如画中画电视?_C#_.net_Wpf_Xaml - Fatal编程技术网

C# 我是否可以将XAML/WPF窗口复制到第二个窗口中,如画中画电视?

C# 我是否可以将XAML/WPF窗口复制到第二个窗口中,如画中画电视?,c#,.net,wpf,xaml,C#,.net,Wpf,Xaml,我有一个具有两个XAML/WPF窗口(源自NavigationWindow)的应用程序,每个窗口包含一个父用户控件,所有子控件都放在其中。在其中一个窗口中,我想以画中画电视的方式显示第二个窗口的内容(实际上只是父用户控件)。通过这种方式,用户可以查看第一个窗口,同时查看第二个窗口中发生的事情。注意,我不想要第二个窗口的UserControl的两个独立副本(这很容易),而是在第一个窗口中镜像第二个窗口的内容 这与Windows7任务栏缩略图预览有点相似,所以我认为它一定是可行的。然而,理想情况下,

我有一个具有两个XAML/WPF窗口(源自NavigationWindow)的应用程序,每个窗口包含一个父用户控件,所有子控件都放在其中。在其中一个窗口中,我想以画中画电视的方式显示第二个窗口的内容(实际上只是父用户控件)。通过这种方式,用户可以查看第一个窗口,同时查看第二个窗口中发生的事情。注意,我不想要第二个窗口的UserControl的两个独立副本(这很容易),而是在第一个窗口中镜像第二个窗口的内容

这与Windows7任务栏缩略图预览有点相似,所以我认为它一定是可行的。然而,理想情况下,我也希望能够与窗口中的窗口进行交互,就像我打开原始窗口一样

这与类似,只是我希望复制同一应用程序中的单个窗口,而不是整个桌面。也类似于,但我需要更多的手,因为我对C#/WPF不是非常熟悉。一些代码片段会很棒


提前谢谢你

使用可视笔刷填充矩形

但是你将无法与它交互。。。但这就是如何在任务栏上预览缩略图

<Grid HorizontalAlignment="Left" Name="A" Height="100" Width="100">
    <Grid.Background>
        <SolidColorBrush Opacity="0" Color="White"/>
    </Grid.Background>
    <!-- Contents -->
</Grid>


<Rectangle Name="RA" VerticalAlignment="Top" Width="100" Height="100" HorizontalAlignment="Left" Stroke="Black">
    <Rectangle.Fill>
        <!-- Creates the reflection. -->
        <VisualBrush  AutoLayoutContent="True"  Visual="{Binding ElementName=A}" ViewboxUnits="RelativeToBoundingBox" ViewportUnits="RelativeToBoundingBox" Stretch="Fill" AlignmentX="Left" AlignmentY="Top" Viewport="0,0,1,1" Viewbox="0,0,1,1" TileMode="None">
        </VisualBrush>
    </Rectangle.Fill>
</Rectangle>

要进行交互,您必须将所有属性绑定到相同的屏幕,并使用布局变换来缩小屏幕

<StackPanel>
    <Grid>
        <TextBox Name="A"/>
    </Grid>
    <Grid>
        <Grid.LayoutTransform>
            <ScaleTransform CenterX=".5" CenterY=".5"  ScaleX=".25" ScaleY=".25"/>
        </Grid.LayoutTransform>
        <TextBox Name="B" Text="{Binding ElementName=A, Path=Text, UpdateSourceTrigger=PropertyChanged}"/>
    </Grid>
</StackPanel>

使用可视笔刷。它不会是交互式的,但似乎适合您的需要

将此代码粘贴到中以查看其实际操作

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Page.Triggers>
        <EventTrigger RoutedEvent="Page.Loaded">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard Storyboard.TargetName="sampleAnimation" Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(RotateTransform.Angle)">
                        <DoubleAnimation Duration="00:00:10" RepeatBehavior="Forever" To="-360">
                            <DoubleAnimation.EasingFunction>
                                <ElasticEase/>
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Page.Triggers>
    <Page.Resources>
        <VisualBrush x:Key="contentBrush" Stretch="None" Visual="{Binding ElementName=content}"/>
    </Page.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <TextBlock FontSize="25" Text="Content to mirror:"/>
        <Grid
            x:Name="content"
            Grid.Row="1"
            Margin="5"
            Background="#11000000"
            ClipToBounds="True">
            <TextBox
                x:Name="sampleAnimation"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                FontSize="60"
                FontWeight="Light"
                Foreground="Red"
                RenderTransformOrigin="0.5,0.5"
                Text="Hello!">
                <TextBox.RenderTransform>
                    <RotateTransform Angle="0"/>
                </TextBox.RenderTransform>
            </TextBox>
        </Grid>
        <TextBlock Grid.Row="2" FontSize="25" Text="Mirrored content using VisualBrush:"/>
        <Grid Grid.Row="3" Background="{StaticResource contentBrush}">
        </Grid>
    </Grid>
</Page>

您可以“劫持”第二个窗口的内容,并将其放入“PiP”控件中。当不再需要PiP时,如果需要,将内容重新附加回窗口。