Hosting a WPF application within a Win32 application can be very cumbersome when it comes to application wide resources. By default there is no Application.Current set when a WPF application is hosted and the dispatcher thread is part of the Win32 world. In an article of Dr. WPF he describes, how such an Application.Current can be created by your own.
His method works very well but when it comes to replace a merged dictionary (e.g. for doing some kind of “skin” change during runtime), the following tweak seems to be required:
// This window is required that Resource changes (like new skin)
// are propagated to all windows and controls
var window = new Window();
window.Content = shell;
IntPtr hwndParent = new IntPtr(1); // Here you need the window handle of the parent window
HwndSourceParameters parameters = new HwndSourceParameters();
parameters.WindowStyle = (int)(WS_VISIBLE | WS_CHILD);
parameters.ParentWindow = hwndParent;
hwndSource = new HwndSource(parameters);
hwndSource.RootVisual = shell;
hwndSource.SizeToContent = System.Windows.SizeToContent.Manual;
Abonnieren
Kommentare zum Post (Atom)
1 Kommentar:
Can you explain a bit the logic here. I'm not sure I understand fully where the "shell" object should be!
Kommentar veröffentlichen