2011-07-20 8 views
0

私は多くの異なるウィンドウを持っていて、それらはすべて異なるデザインです。メニューはさまざまなウィンドウが選択されています。メニューには、すべての行のウィンドウのスクリーンショットがあります。 、WPFを使用した動的ウィンドウプレビュー生成

  1. は、ウィンドウのスクリーンショットが
  2. が新しいウィンドウ
  3. リンククリックハンドラ

そうに画像を挿入します:私は方法を見つけると、次の手順を自動化したいと思います実際に私の質問は、ランタイム中にまだ隠されたウィンドウのイメージを取得することが可能かどうかです

答えて

1

これはアイデアを与える必要があります。私は自分のウィンドウ用のコントロールテンプレートを持っています。このテンプレートには、各インスタンスの他のすべてのコントロールをラップするVisualTarget要素があります。したがって、以下のコードは私のために働きます。

class ThumbnailView 
{ 
    public Guid WindowGuid { get; set; } 
    public Window ApplicationWindowInstance { get; set; } 
    public Border ThumbnailVisual 
    { 
     get { 
      return (this.ApplicationWindowInstance. 
          Template.FindName("VisualTarget", 
          this.ApplicationWindowInstance) as Border); 
     } 
    } 
} 

<Border BorderThickness="0,0,0,0" Cursor="Hand"> 
    <Border.Background> 
     <VisualBrush Visual="{Binding ThumbnailVisual}"/> 
    </Border.Background> 
</Border> 


編集:ここでは、より一般的なものである

ObservableCollection<WindowInstance> _windows = new ObservableCollection<WindowInstance>(); 

class WindowInstance 
{ 
    public Window CurrentWindowInstance { get; set; } 
    public DependencyObject CurrentVisual { 
     get { 
      return VisualTreeHelper.GetChild(CurrentWindowInstance, 0); 
     } 
    } 
} 

<ItemsControl ItemsSource="{Binding}"> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <StackPanel></StackPanel> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      <Border BorderThickness="0,0,0,0" Width="50" Height="50"> 
       <Border.Background> 
        <VisualBrush Visual="{Binding CurrentVisual}"/> 
       </Border.Background> 
      </Border> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 


編集:上記の性能を破壊につながる可能性があり、ライブのビジュアルブラシを使用している例。だから、フリーズしたウィンドウのサムネイルの答えは次のとおりです。

ObservableCollection<BitmapFrame> _windowCaptures = new ObservableCollection<BitmapFrame>(); 

TestWindow testWindow = new TestWindow(); 
RenderTargetBitmap bitmap = new RenderTargetBitmap((int)testWindow.Width, (int)testWindow.Height, 96, 96, 
             PixelFormats.Pbgra32); 
bitmap.Render((Visual)VisualTreeHelper.GetChild(testWindow, 0)); 
_windowCaptures.Add(BitmapFrame.Create(bitmap)); 

<ItemsControl ItemsSource="{Binding}"> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <StackPanel></StackPanel> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      <Image Height="100" Width="100" Source="{Binding}"></Image> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 
関連する問題