private IntPtr InitializePresenterCoreWindowMode(HandleRef hwndParent) { CoreWindow coreWindow = CoreWindowInterop.CreateCoreWindow("XAMLONWIN32", 0, 0, 0, 0); ICoreApplicationPrivate2 coreApp = new ICoreApplicationPrivate2(); coreApp.CreateNonImmersiveView(); XamlPresenterStatics3 xamlPresenterStatics = new XamlPresenterStatics3(); XamlPresenter presenter = xamlPresenterStatics.CreateFromCoreWindow(coreWindow); ICoreWindowInterop interop = new ICoreWindowInterop(coreWindow); IntPtr windowHandle = interop.GetWindowHandle(); int style = Win32Interop.GetWindowStyle(windowHandle); style = style & (~WindowStyles.WS_POPUP); style = style | WindowStyles.WS_CHILD; Win32Interop.SetWindowStyle(windowHandle, style); Win32Interop.SetParent(windowHandle, hwndParent.Handle); presenter.InitializePresenter(); return(windowHandle); }
protected override HandleRef BuildWindowCore(HandleRef hwndParent) { Win32Interop.EnableMouseInPointer(); // There are several different low-level interfaces available at this time. // Use XamlBridge unless you have a known reason to use the others. //IntPtr windowHandle = InitializePresenterHwndMode(hwndParent); //IntPtr windowHandle = InitializePresenterCoreWindowMode(hwndParent); IntPtr windowHandle = InitializeBridge(hwndParent); // Uncomment the following lines to create Xaml UI content directly from within this WPF host control. // Normally, the user of this control sets a property which is the name of a Xaml UserControl to instantiate. Windows.UI.Xaml.Controls.StackPanel panel = new Windows.UI.Xaml.Controls.StackPanel(); panel.Orientation = Windows.UI.Xaml.Controls.Orientation.Vertical; panel.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Red); Windows.UI.Xaml.Controls.TextBox textBox = new Windows.UI.Xaml.Controls.TextBox(); textBox.Text = "XAML TextBox 1"; panel.Children.Add(textBox); Windows.UI.Xaml.Controls.Button button = new Windows.UI.Xaml.Controls.Button(); button.Content = "XAML Button"; panel.Children.Add(button); textBox = new Windows.UI.Xaml.Controls.TextBox(); textBox.Text = "XAML TextBox 2"; panel.Children.Add(textBox); //XamlClassLibrary.TestUserControl testUserControl = new XamlClassLibrary.TestUserControl(); //panel.Children.Add(testUserControl); Windows.UI.Xaml.Window.Current.Content = panel; panel.LayoutUpdated += XamlContentLayoutUpdated; XamlApplication application = new XamlApplication(); String globalResourceFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "globalresources.xbf"); if (File.Exists(globalResourceFile)) { Windows.UI.Xaml.Application.LoadComponent(application, new Uri("ms-resource:///Files/globalresources.xaml")); } Windows.UI.Xaml.FrameworkElement contentRoot = panel; //var type = Type.GetType(ControlType, true, true); //Windows.UI.Xaml.FrameworkElement contentRoot = (Windows.UI.Xaml.FrameworkElement) Activator.CreateInstance("XamlClassLibrary", ControlType).Unwrap(); Windows.UI.Xaml.Window.Current.Content = contentRoot; contentRoot.LayoutUpdated += XamlContentLayoutUpdated; return(new HandleRef(this, windowHandle)); }
private IntPtr InitializePresenterHwndMode(HandleRef hwndParent) { Win32Interop.RegisterWindowClass(WINDOW_CLASS_NAME, WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW); IntPtr windowHandle = Win32Interop.CreateWindow( WINDOW_CLASS_NAME, WindowStyles.WS_CHILD | WindowStyles.WS_VISIBLE | WindowStyles.WS_CLIPCHILDREN, 0, 0, 0, 0, hwndParent.Handle); XamlPresenterStatics xamlPresenterStatics = new XamlPresenterStatics(); XamlPresenter presenter = xamlPresenterStatics.CreateFromHwnd((int)windowHandle); presenter.InitializePresenter(); return(windowHandle); }
protected override bool TabIntoCore(TraversalRequest request) { Windows.UI.Xaml.DependencyObject elementToFocus; if (request.FocusNavigationDirection == FocusNavigationDirection.First) { elementToFocus = Windows.UI.Xaml.Input.FocusManager.FindFirstFocusableElement(null); } else { elementToFocus = Windows.UI.Xaml.Input.FocusManager.FindLastFocusableElement(null); } if (elementToFocus is Windows.UI.Xaml.Controls.Control) { Win32Interop.FocusWindow(Handle); ((Windows.UI.Xaml.Controls.Control)elementToFocus).Focus(Windows.UI.Xaml.FocusState.Keyboard); return(true); } return(false); }
protected override void DestroyWindowCore(HandleRef hwnd) { Win32Interop.DestroyWindow(hwnd.Handle); // TODO: this is the best place to explicitly tear down the XamlBridge }