private void UseHelperMethod() { var myHostControl = new WindowsXamlHost(); myHostControl.Dock = DockStyle.Fill; // Use helper method to create a UWP control instance. uwpButton = UWPTypeFactory.CreateXamlContentByType("Windows.UI.Xaml.Controls.Button") as Windows.UI.Xaml.Controls.Button; // Initialize UWP control. uwpButton.Name = "button1"; uwpButton.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch; uwpButton.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch; uwpButton.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Red); uwpButton.Click += delegate { uwpButton.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Blue); }; // initialize the Windows XAML host control. myHostControl.Name = "myWindowsXamlHostControl"; myHostControl.Child = uwpButton; // Make the UWP control appear in the UI. this.Controls.Add(myHostControl); }
private void CreateTimePicker(Size size, Point point) { WindowsXamlManager.InitializeForCurrentThread(); TimePicker control = new TimePicker { Name = "timePicker", Width = size.Width, Height = size.Height, TabIndex = 0 }; control.TimeChanged += Control_TimeChanged; control.SelectedTimeChanged += Control_SelectedTimeChanged; WindowsXamlHost myHostControl = new WindowsXamlHost { Location = point, Size = size, Name = "host1", Child = control }; this.PanelContent.Controls.Add(myHostControl); }
private void CreateCalendar(Size size, Point point) { // Initialize the UWP hosting environment. WindowsXamlManager.InitializeForCurrentThread(); // Create a UWP control. CalendarDatePicker calendar = new CalendarDatePicker { Name = "calendar", Width = size.Width, Height = size.Height, TabIndex = 0, PlaceholderText = "Select Date", //Header = "Test Calendar" }; calendar.Closed += Calendar_Closed; // Create a Windows XAML host control. WindowsXamlHost myHostControl = new WindowsXamlHost { Location = point, Size = size, Name = "host2", Child = calendar }; // Make the UWP control appear in the UI. // For Windows Forms applications, you might use this.Controls.Add(myHostControl); this.PanelContent.Controls.Add(myHostControl); }
private void PrepareWindowsXamlHost() { _xamlHost = new WindowsXamlHost(); OnPreparingXamlHost(_xamlHost); Content = _xamlHost; }
private void WindowsXamlHost_ChildChanged(object sender, EventArgs e) { // Hook up x:Bind source. WindowsXamlHost windowsXamlHost = sender as WindowsXamlHost; ShellPage shellPage = windowsXamlHost.GetUwpInternalObject() as ShellPage; if (shellPage != null) { // send IPC Message shellPage.SetDefaultSndMessageCallback(msg => { //IPC Manager is null when launching runner directly Program.GetTwoWayIPCManager()?.Send(msg); }); // send IPC Message shellPage.SetRestartAdminSndMessageCallback(msg => { Program.GetTwoWayIPCManager().Send(msg); System.Windows.Application.Current.Shutdown(); // close application }); shellPage.SetElevationStatus(Program.IsElevated); shellPage.Refresh(); } }
private async void GpuViewHost_ChildChanged(object sender, EventArgs e) { WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender; SwapChainPanel swapChainPanel = (SwapChainPanel)windowsXamlHost.Child; GpuView = swapChainPanel; Gpu = new Gpu(); #if DEBUG Gpu.EnableD3D12DebugLayer(); #endif GpuView.Width = this.Width; GpuView.Height = this.Height; await Init(); SizeChanged += MainWindow_SizeChanged; GpuFence fence = Device.DefaultQueue.CreateFence(); UInt64 currentFenceValue = 0; while (true) { if (SwapChain == null) { SwapChainDescriptor = new GpuSwapChainDescriptor(GpuTextureFormat.BGRA8UNorm, (uint)GpuView.Width, (uint)GpuView.Height); SwapChain = Device.ConfigureSwapChainForSwapChainPanel(SwapChainDescriptor, GpuView); DepthTexture = Device.CreateTexture(new GpuTextureDescriptor(new GpuExtend3DDict { Width = SwapChainDescriptor.Width, Height = SwapChainDescriptor.Height, Depth = 1 }, GpuTextureFormat.Depth24PlusStencil8, GpuTextureUsageFlags.OutputAttachment)); } DrawFrame(); var fenceValueWaitFor = ++currentFenceValue; Device.DefaultQueue.Signal(fence, fenceValueWaitFor); await fence.OnCompletionAsync(fenceValueWaitFor); } }
private void XamlHost_ChildChanged(object sender, EventArgs e) { WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender; Windows.UI.Xaml.Controls.FlipView flipView = (Windows.UI.Xaml.Controls.FlipView)windowsXamlHost.Child; if (flipView == null) { return; } var dataTemplate = (Windows.UI.Xaml.DataTemplate)XamlReader.Load(@" <DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""> <Grid Margin=""5""> <Grid.RowDefinitions> <RowDefinition Height=""*"" /> <RowDefinition Height=""40"" /> </Grid.RowDefinitions> <Image Source=""{Binding PhotoUrl}"" Grid.Row=""0"" Margin=""5"" Stretch=""Uniform"" /> <TextBlock Text=""{Binding UserName}"" HorizontalAlignment=""Center"" VerticalAlignment=""Center"" Grid.Row=""1""/> </Grid> </DataTemplate>"); flipView.ItemTemplate = dataTemplate; flipView.ItemsSource = ((MainViewModel)DataContext).Photos; }
private void WindowsXamlHost_ChildChanged(object sender, EventArgs e) { if (sender == null) { return; } WindowsXamlHost windowsXamlHost = sender as WindowsXamlHost; shellPage = windowsXamlHost.GetUwpInternalObject() as OobeShellPage; OobeShellPage.SetRunSharedEventCallback(() => { return(Constants.PowerLauncherSharedEvent()); }); OobeShellPage.SetColorPickerSharedEventCallback(() => { return(Constants.ShowColorPickerSharedEvent()); }); OobeShellPage.SetOpenMainWindowCallback((Type type) => { ((App)Application.Current).OpenSettingsWindow(type); }); }
protected virtual WindowsXamlHost OnPreparingXamlHost(WindowsXamlHost xamlHost) { xamlHost.InitialTypeName = typeof(TXamlContent).FullName; xamlHost.HorizontalAlignment = HorizontalAlignment.Stretch; xamlHost.VerticalAlignment = VerticalAlignment.Stretch; return(xamlHost); }
/// <summary> /// Create / Host UWP CaptureElement /// </summary> private void GetUwpCaptureElement() { XamlHostCaptureElement = new WindowsXamlHost { InitialTypeName = "Windows.UI.Xaml.Controls.CaptureElement" }; XamlHostCaptureElement.ChildChanged += XamlHost_ChildChangedAsync; }
private void ConfirmButton_Click(object sender, RoutedEventArgs e) { error.Content = ""; ClassroomEntry selectedClassroom = (ClassroomEntry)_classroomComboBox.SelectedItem; RoomEntry selectedRoom = (RoomEntry)_roomNameComboBox.SelectedItem; int repetitivity = _regularityComboBox.SelectedIndex; WindowsXamlHost windowsHost = _timePicker; TimePicker timePickerHour = (TimePicker)windowsHost.Child; WindowsXamlHost windowsHost2 = _durationTimePicker; TimePicker durationTimePicker = (TimePicker)windowsHost2.Child; TimeSpan? durationTimeSelected = durationTimePicker.SelectedTime; if (durationTimeSelected == null) { error.Foreground = new SolidColorBrush(Colors.Red); error.Content = "Spécifier une durée"; return; } TimeSpan?hourTimeSelected = timePickerHour.SelectedTime; if (hourTimeSelected == null) { error.Foreground = new SolidColorBrush(Colors.Red); error.Content = "Spécifier une heure."; return; } DateTime?dateSelected = _firstDatePciker.SelectedDate; if (dateSelected == null) { error.Foreground = new SolidColorBrush(Colors.Red); error.Content = "Spécifier une date de première séance"; return; } DateTime dateSelectedNotNull = (DateTime)dateSelected; dateSelectedNotNull = dateSelectedNotNull.AddHours((double)hourTimeSelected?.Hours).AddMinutes((double)hourTimeSelected?.Minutes); int scheduleId = Database.Insert.Schedule.One(selectedClassroom.ID, selectedRoom.ID, repetitivity, dateSelectedNotNull, (TimeSpan)hourTimeSelected); ScheduleOption.ScheduleOptionDisplay scheduleDisplay = new ScheduleOption.ScheduleOptionDisplay() { ID = scheduleId, ClassroomId = selectedClassroom.ID, NextDate = dateSelectedNotNull.ToString("g", GlobalVariable.culture), Duration = durationTimeSelected?.ToString(@"hh\:mm"), Repetitivity = repetitivity == 0 ? "Une fois par semaine" : "Une semaine sur deux", Room = Database.Get.Room.NameFromID(selectedRoom.ID) }; //TODO: Make this work but not mendatory for now //ScheduleOption.scheduleDisplayCollection.Add(scheduleDisplay); error.Foreground = new SolidColorBrush(Colors.Green); error.Content = "Horaire ajouté avec succès"; }
private void WindowsXamlHost_ChildChanged(object sender, EventArgs e) { // Hook up x:Bind source. WindowsXamlHost windowsXamlHost = sender as WindowsXamlHost; ShellPage shellPage = windowsXamlHost.GetUwpInternalObject() as ShellPage; if (shellPage != null) { // send IPC Message shellPage.SetDefaultSndMessageCallback(msg => { // IPC Manager is null when launching runner directly Program.GetTwoWayIPCManager()?.Send(msg); }); // send IPC Message shellPage.SetRestartAdminSndMessageCallback(msg => { Program.GetTwoWayIPCManager().Send(msg); System.Windows.Application.Current.Shutdown(); // close application }); // send IPC Message shellPage.SetCheckForUpdatesMessageCallback(msg => { Program.GetTwoWayIPCManager().Send(msg); }); // receive IPC Message Program.IPCMessageReceivedCallback = (string msg) => { if (ShellPage.ShellHandler.IPCResponseHandleList != null) { try { JsonObject json = JsonObject.Parse(msg); foreach (Action <JsonObject> handle in ShellPage.ShellHandler.IPCResponseHandleList) { handle(json); } } catch (Exception) { } } }; shellPage.SetElevationStatus(Program.IsElevated); shellPage.SetIsUserAnAdmin(Program.IsUserAnAdmin); shellPage.Refresh(); } // XAML Islands: If the window is open, explicity force it to be shown to solve the blank dialog issue https://github.com/microsoft/PowerToys/issues/3384 if (isOpen) { Show(); } }
private void Host_ChildChanged(object sender, EventArgs e) { WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender; Windows.UI.Xaml.Controls.TextBlock textBlock = (Windows.UI.Xaml.Controls.TextBlock)windowsXamlHost.Child; textBlock.Text = "❤❤❤❤😍😍😍😍"; }
private void WindowsXamlHost_ChildChanged(object sender, EventArgs e) { WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender; // 利用 Windows.UI.Xaml.Controls 做為轉換 Windows.UI.Xaml.Controls.Button button = (Windows.UI.Xaml.Controls.Button)windowsXamlHost.Child; Windows.UI.Xaml.Controls.TextBlock txt = new Windows.UI.Xaml.Controls.TextBlock(); txt.Text = "123"; button.Content = txt; }
private void btnAddMovie_ChildChanged(object sender, EventArgs e) { WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender; UWP.ButtonControl ctl = windowsXamlHost.Child as UWP.ButtonControl; if (ctl != null) { ctl.ButtonCommand = new SimpleCommand((obj) => Add_Movie(), (obj) => true); } }
private void CreateTreeview(Size size, Point point) { WindowsXamlManager.InitializeForCurrentThread(); treeView = new Windows.UI.Xaml.Controls.TreeView { Width = size.Width, Height = size.Height, }; List <TreeViewNode> items = new List <TreeViewNode>(); for (int i = 0; i < 20; i++) { var item = new TreeViewNode { Content = "Item " + i }; for (int c = 0; c < 20; c++) { item.Children.Add(new TreeViewNode { Content = "SubItem " + c }); } treeView.RootNodes.Add(item); } treeView.ItemInvoked += TreeView_ItemInvoked; ScrollViewer scroll = new ScrollViewer { Name = "scroll", Content = treeView, Width = treeView.Width, Height = size.Height }; try { WindowsXamlHost myHostControl = new WindowsXamlHost { Location = point, Size = size, Name = "myHostControl", Child = scroll }; this.Controls.Add(myHostControl); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public Form1() { InitializeComponent(); Windows.UI.Xaml.Hosting.WindowsXamlManager.InitializeForCurrentThread(); var host = new WindowsXamlHost(); host.Child = (new Demo()).Do(); host.Width = this.Width - this.Margin.Horizontal * 2; host.Height = this.Height; this.Controls.Add(host); }
private void MyNavView_OnChildChanged(object sender, EventArgs e) { WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender; var tempCaptureElement = (CaptureElement)windowsXamlHost.Child; if (tempCaptureElement != null) { _captureElement = tempCaptureElement; PrepareCamera(); } }
public UwpImageControl() { InitializeComponent(); var uwphost = new WindowsXamlHost(); uwphost.Parent = this; uwphost.Dock = DockStyle.Fill; uwphost.Visible = true; uwphost.InitialTypeName = "Windows.UI.Xaml.Controls.Image"; uwphost.ChildChanged += Uwphost_ChildChanged; }
protected override WindowsXamlHost OnPreparingXamlHost(WindowsXamlHost xamlHost) { xamlHost.Height = 0; xamlHost.Width = 0; Dispatcher.BeginInvoke(new Action(() => { Hide(); }), DispatcherPriority.ContextIdle, null); return(base.OnPreparingXamlHost(xamlHost)); }
private void MyUWPPage_ChildChanged(object sender, EventArgs e) { // Hook up x:Bind source WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender; global::MyUWPControls.BlankPage1 myUWPPage = windowsXamlHost.GetUwpInternalObject() as global::MyUWPControls.BlankPage1; if (myUWPPage != null) { myUWPPage.WPFMessage = this.WPFMessage; } }
private void SharedXamlHost_ChildChanged(object sender, EventArgs e) { if (EventSet == false) { WindowsXamlHost windowsXamlHost = sender as Microsoft.Toolkit.Wpf.UI.XamlHost.WindowsXamlHost;; UWPSharedPanel.RealEstateComponent sharedPanel = windowsXamlHost.GetUwpInternalObject() as UWPSharedPanel.RealEstateComponent; sharedPanel.StringChanged += OnStringChanged; EventSet = true; } }
private void OnButtonChanged(object sender, EventArgs e) { WindowsXamlHost wxh = (WindowsXamlHost)sender; Windows.UI.Xaml.Controls.Button btn = wxh.Child as Windows.UI.Xaml.Controls.Button; if (btn != null) { btn.Height = 100; btn.Width = 200; btn.Content = "Hello World"; btn.Click += OnClick; } }
private void OnStackPanelChanged(object sender, EventArgs e) { WindowsXamlHost wxh = (WindowsXamlHost)sender; Windows.UI.Xaml.Controls.StackPanel stackPanel = wxh.Child as Windows.UI.Xaml.Controls.StackPanel; if (stackPanel != null) { list = new Windows.UI.Xaml.Controls.ListView(); list.Items.Add("One"); list.Items.Add("Two"); list.Items.Add("Three"); stackPanel.Children.Add(list); } }
private void WindowsXamlHost_ChildChanged(object sender, EventArgs e) { WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender; var navView = (NavigationView)windowsXamlHost.Child; if (navView != null) { navView.PaneDisplayMode = NavigationViewPaneDisplayMode.Left; navView.MenuItems.Add(CreateMenu("Mouse", "\uF71E")); navView.MenuItems.Add(CreateMenu("Pen", "\uE76D")); navView.MenuItems.Add(CreateMenu("Touch", "\uED5F")); navView.ItemInvoked += NavView_ItemInvoked; } }
private void WindowsXamlHost_ChildChanged(object sender, EventArgs e) { WindowsXamlHost host = sender as WindowsXamlHost; if (host == null) { return; } if (host.Child is TextBox tb) { tb.PlaceholderText = "Enter your name"; tb.Width = 120; tb.Height = 32; tb.Margin = new Windows.UI.Xaml.Thickness(2); Binding binding = new Binding { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Source = _vm, Path = new Windows.UI.Xaml.PropertyPath("YourName") }; BindingOperations.SetBinding(tb, TextBox.TextProperty, binding); } else if (host.Child is Button btn) { btn.Content = "Say Hello"; btn.Width = 80; btn.Height = 32; btn.Margin = new Windows.UI.Xaml.Thickness(2); btn.Click += async(_, __) => { await new Windows.UI.Popups.MessageDialog($"Hello {_vm?.YourName}", "UWP 消息框").ShowAsync(); }; Binding binding = new Binding() { Mode = BindingMode.OneWay, Source = DataContext, Path = new Windows.UI.Xaml.PropertyPath("CanSayHello") }; BindingOperations.SetBinding(btn, Button.IsEnabledProperty, binding); } else { // } }
private void CalendarUwp_ChildChanged(object sender, System.EventArgs e) { WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender; Windows.UI.Xaml.Controls.CalendarView calendarView = (Windows.UI.Xaml.Controls.CalendarView)windowsXamlHost.Child; if (calendarView != null) { calendarView.SelectedDatesChanged += (obj, args) => { if (args.AddedDates.Count > 0) { Messenger.Default.Send <SelectedDateMessage>(new SelectedDateMessage(args.AddedDates[0].DateTime)); } }; } }
public ImportBooks() { InitializeComponent(); _jsonPath = Path.Combine(Application.StartupPath, "bookData.txt"); spaces = spaces.ReadFromDataStore(_jsonPath); var windowsXamlHostTreeView = new WindowsXamlHost(); windowsXamlHostTreeView.InitialTypeName = "Windows.UI.Xaml.Controls.TreeView"; windowsXamlHostTreeView.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly; windowsXamlHostTreeView.Location = new System.Drawing.Point(12, 60); windowsXamlHostTreeView.Name = "tvFoundBooks"; windowsXamlHostTreeView.Size = new System.Drawing.Size(513, 350); windowsXamlHostTreeView.TabIndex = 8; windowsXamlHostTreeView.Dock = System.Windows.Forms.DockStyle.None; windowsXamlHostTreeView.ChildChanged += windowsXamlHostTreeView_ChildChanged; this.Controls.Add(windowsXamlHostTreeView); }
/// <summary> /// This method is used to wrap the Windows.UI.Xaml control in a new instance of a WindowsXamlHost. /// </summary> /// <param name="windowsXamlHost"></param> /// <param name="control"></param> /// <returns>Control</returns> internal Control WrapInXamlHost(WindowsXamlHost windowsXamlHost, WUX.Controls.Control control) { windowsXamlHost.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly; windowsXamlHost.InitialTypeName = null; windowsXamlHost.Padding = new Padding(5); WUX.Controls.StackPanel stackPanel = new WUX.Controls.StackPanel() { HorizontalAlignment = WUX.HorizontalAlignment.Stretch }; stackPanel.Children.Add(control); windowsXamlHost.Child = stackPanel; if (windowsXamlHost.Width == 0) { windowsXamlHost.Height = ((int)control.Height > 0) ? (int)control.Height + 100 : 80; windowsXamlHost.Width = ((int)control.Width > 0) ? (int)control.Width + 220 : 500; } return(windowsXamlHost); }
private void CalendarUwp_ChildChanged(object sender, EventArgs e) { WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender; Windows.UI.Xaml.Controls.CalendarView calendarView = (Windows.UI.Xaml.Controls.CalendarView)windowsXamlHost.Child; if (calendarView != null) { calendarView.SelectedDatesChanged += (obj, args) => { if (calendarView.SelectedDates.Count > 0) { SelectedDate = calendarView.SelectedDates.FirstOrDefault().DateTime; txtDate.Text = SelectedDate.ToShortDateString(); } }; calendarView.MinDate = DateTimeOffset.Now.AddYears(-1); calendarView.MaxDate = DateTimeOffset.Now; } }