-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WPF - Update CleanupElement when PresentationSource changes
- If the CleanupElement is a Window then move it to the new Window
- Loading branch information
Showing
3 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Window x:Class="CefSharp.Wpf.Example.ChangeParentWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Title="ChangeParentWindow" Height="600" Width="800" WindowStartupLocation="CenterScreen" WindowState="Maximized"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="*" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition /> | ||
<ColumnDefinition /> | ||
</Grid.ColumnDefinitions> | ||
<StackPanel Orientation="Horizontal" Grid.ColumnSpan="2"> | ||
<Button Content="Open browser in new Window" Click="OnAddBrowser" /> | ||
<Button Content="Re-Parent Browser and Close Window" Click="OnRemoveBrowser" /> | ||
</StackPanel> | ||
<Border Grid.Row="1" Grid.Column="0" x:Name="StaticBrowser" /> | ||
<Border Grid.Row="1" x:Name="BrowserSite" Grid.Column="1" /> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright © 2022 The CefSharp Authors. All rights reserved. | ||
// | ||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. | ||
|
||
using System.Windows; | ||
|
||
namespace CefSharp.Wpf.Example | ||
{ | ||
/// <summary> | ||
/// Interaction logic for ChangeParentWindow.xaml | ||
/// </summary> | ||
public partial class ChangeParentWindow : Window | ||
{ | ||
private ChromiumWebBrowser browser; | ||
private Window newWindow; | ||
|
||
public ChangeParentWindow() | ||
{ | ||
InitializeComponent(); | ||
|
||
StaticBrowser.Child = new ChromiumWebBrowser("http://www.msn.net"); | ||
} | ||
|
||
private void OnAddBrowser(object sender, RoutedEventArgs e) | ||
{ | ||
if (browser == null) | ||
{ | ||
browser = new ChromiumWebBrowser("http://www.msn.net"); | ||
} | ||
|
||
if (newWindow == null) | ||
{ | ||
newWindow = new Window | ||
{ | ||
Owner = this, | ||
Content = browser, | ||
WindowStartupLocation = WindowStartupLocation.CenterOwner | ||
}; | ||
|
||
newWindow.Show(); | ||
} | ||
} | ||
|
||
private void OnRemoveBrowser(object sender, RoutedEventArgs e) | ||
{ | ||
if (newWindow != null) | ||
{ | ||
newWindow.Content = null; | ||
newWindow.Close(); | ||
newWindow = null; | ||
} | ||
|
||
BrowserSite.Child = browser; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters