c# - 我能否将 XAML/WPF 窗口复制到第二个窗口中,例如画中画电视?

标签 c# .net wpf xaml

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

这有点类似于 Windows 7 任务栏缩略图预览,所以我认为它一定是可行的。然而,理想情况下,我还希望能够与那个窗口中的窗口进行交互,就像我拉起原始窗口时一样。

这类似于 this question ,除了我只想复制同一应用程序中的一个窗口,而不是整个桌面。也类似于 this question ,但我需要更多的掌握,因为我对 C#/WPF 不是很熟悉。一些代码片段会很棒。

提前致谢!

最佳答案

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

将此代码粘贴到 Kaxaml 中以查看实际效果。

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

关于c# - 我能否将 XAML/WPF 窗口复制到第二个窗口中,例如画中画电视?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11782225/

相关文章:

c# - MEF 容器层次结构和 GetExports<T>

wpf - 样式或资源中的WPF DataGrid列

c# - 如何将此字符串转换为日期?

c# - Visual Studio 2017 本地化发布设置

c# - 在 C# 中从 PictureBox 中删除图像

.net - COM 字符串 (BSTR) 和 .NET 字符串有什么区别?

.net - 如何检查文件名是否与通配符模式匹配?

c# - .net Core Quartz 依赖注入(inject)

c# - ListBox 知道它在某个遥远的 ScrollViewer 中吗?

c# - 如何启用/禁用按钮?