我可以复制一个XAML / WPF窗口到第二个窗口,如子母画面电视? [英] Can I duplicate a XAML/WPF window into a second window, like a picture-in-picture TV?

查看:188
本文介绍了我可以复制一个XAML / WPF窗口到第二个窗口,如子母画面电视?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个XAML / WPF窗口的应用程序(从NavigationWindow派生),每个窗口都包含一个父用户控件,所有子控件放置。在其中一个窗口,我想显示第二个窗口的内容(其实只是父用户控件),像一个子母画面电视的方式。以这种方式,用户可以观看第一窗口,并且看到什么是在同一时间发生在所述第二窗口。请注意,我不希望这第二个窗口的用户控件的两个独立的副本(这将是容易的),而是要反映第二个窗口的第一个窗口中的内容。

I've got an application with two XAML/WPF windows (derived from NavigationWindow), each window contains one parent UserControl, in which all child controls are placed. In one of the windows, I'd like to show the second window's content (really just the parent UserControl), in the manner like a picture-in-picture TV. In this way the user could view the first window, and see what is happening in the second window at the same time. Note, that I do not want two independent copies of this second window's UserControl (that would be easy), but to mirror the content of the second window in the first window.

这是隐约类似于Windows 7的任务栏缩略图previews,所以我的数字,它必须是可行的。理想情况下,但是,我也希望能与该窗口-IN-A-窗口进行交互,以同样的方式,我想如果我是拉上了原来的窗口。

This is vaguely similar to the Windows 7 Taskbar thumbnail previews, so I figure that it must be doable. Ideally, however, I'd also like to be able to interact with that window-in-a-window, in the same way as I would if I were to pull up the original window.

这是类似于<一href="http://stackoverflow.com/questions/10131333/screenshot-of-the-main-wpf-window-under-second-monitor-tv"标题=这个问题>这个问题,但我想只是一个单一的窗口,从同一个应用程序被复制,而不是整个桌面。类似的还有这个问题,但我需要更多手把手,因为我不是超级熟悉C#/ WPF。有些code段将是巨大的。

This is similar to this question, except that I'd like just a single window from the same application to be copied, instead of the whole desktop. Also similar to this question, but I need a bit more hand-holding, as I'm not super-familiar with C#/WPF. Some code snippets would be great.

感谢你在前进!

推荐答案

使用一个可视化笔刷。这不会是互动的,但似乎满足您的需求。

Use a visual brush. It will not be interactive, but that seems to suit your needs.

粘贴此code到 Kaxaml 看到它在行动。

Paste this code into Kaxaml to see it in action.

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

这篇关于我可以复制一个XAML / WPF窗口到第二个窗口,如子母画面电视?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆