As much as I love Microsoft, it's a wonder that they don't update some of their developer controls/tools to use the technology that they are writing everything else in.
Thankfully, the developer community is on top of it.
WPF: Using a Frame element in a custom shaped window
Here's my modified code to enable this functionality as a reusable class:
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Media;
using DrawingPoint = System.Drawing.Point;
namespace VisibleFrame
{
internal class VisibleFrame
{
[DllImport("user32.dll")]
internal static extern bool ClientToScreen(IntPtr hWnd, ref DrawingPoint point);
[DllImport("user32.dll")]
internal static extern bool MoveWindow
(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
Window w = new Window { WindowStyle = WindowStyle.None,
ShowInTaskbar = false, ResizeMode = ResizeMode.NoResize };
Window targetWindow;
Border targetControl;
Frame frame;
internal VisibleFrame
(Window targetWindow, Border targetControl, string initialLocation)
{
this.targetWindow = targetWindow;
this.targetControl = targetControl;
targetWindow.Loaded += WindowLoad;
frame = new Frame();
if(!string.IsNullOrEmpty(initialLocation))
{
Navigate(initialLocation);
}
}
internal void WindowLoad(object sender, RoutedEventArgs e)
{
w.Owner = targetWindow;
w.Content = frame;
targetControl.SizeChanged += delegate { RepaintFrame(); };
targetWindow.LocationChanged += delegate { RepaintFrame(); };
w.Show();
RepaintFrame();
}
private void RepaintFrame()
{
HwndSource hostWindow = HwndSource.FromVisual(targetWindow) as HwndSource;
CompositionTarget ct = hostWindow.CompositionTarget;
Point loc = ct.TransformToDevice.Transform
(targetControl.TranslatePoint(new Point(), targetWindow));
DrawingPoint locD = new DrawingPoint((int)loc.X, (int)loc.Y);
ClientToScreen(hostWindow.Handle, ref locD);
Point size = ct.TransformToDevice.Transform(new Point
(targetControl.ActualWidth, targetControl.ActualHeight));
MoveWindow((HwndSource.FromVisual(w) as HwndSource).Handle,
locD.X, locD.Y, (int)size.X, (int)size.Y, true);
}
internal void Navigate(string location)
{
frame.Navigate(new Uri(location));
}
}
}