2012-08-02 18 views
6

我有一個應用程序與兩個XAML/WPF窗口(從NavigationWindow派生),每個窗口包含一個父UserControl,在其中放置所有子控件。在其中一個窗口中,我想以類似於畫中畫電視的方式顯示第二個窗口的內容(實際上就是父級UserControl)。通過這種方式,用戶可以查看第一個窗口,同時查看第二個窗口中發生了什麼。請注意,我不想要第二個窗口的UserControl的兩個獨立副本(這很容易),而是在第一個窗口中鏡像第二個窗口的內容。我可以將XAML/WPF窗口複製到第二個窗口中,例如畫中畫電視嗎?

這與Windows 7任務欄縮略圖預覽略有相似,所以我認爲它必須可行。然而,理想情況下,我還希望能夠與窗口中的窗口進行交互,就像我將拉起原始窗口一樣。

這與this question類似,只是我想從同一應用程序的一個窗口被複制,而不是整個桌面。也類似於this question,但我需要更多手持,因爲我對C#/ WPF不是很熟悉。一些代碼片段會很好。

預先感謝您!

+0

您可能能夠「劫持」第二個窗口的內容並將它們放入您的「PiP」控件中。當不再需要PiP時,如果需要,將內容重新附加到窗口。 – 2012-08-02 16:57:03

回答

0

使用可視化筆刷作爲矩形的填充。

儘管...你將無法與它交互,但這是如何在任務欄上完成預覽縮略圖。

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

使用可視化畫筆。它不會互動,但似乎適合您的需求。

將此代碼粘貼到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> 
相關問題