private void UpdateXamlRender(string text) { if (XamlCodeEditor == null) { return; } // Hide any Previous Errors XamlCodeEditor.ClearErrors(); // Try and Render Xaml to a UIElement UIElement element = null; try { element = _xamlRenderer.Render(text); } catch (Exception ex) { ShowExceptionNotification(ex); } if (element != null) { // Add element to main panel if (SamplePage == null) { return; } var root = SamplePage.FindDescendantByName("XamlRoot"); if (root is Panel) { // If we've defined a 'XamlRoot' element to host us as a panel, use that. (root as Panel).Children.Clear(); (root as Panel).Children.Add(element); } else { // Otherwise, just replace the entire page's content SamplePage.Content = element; } // Tell the page we've finished with an update to the XAML contents, after the control has rendered. if (element is FrameworkElement fe) { fe.Loaded += XamlFrameworkElement_Loaded; } } else if (_xamlRenderer.Errors.Count > 0) { var error = _xamlRenderer.Errors.First(); XamlCodeEditor.ReportError(error); } }
private void UpdateXamlRender(string text) { if (XamlCodeEditor == null) { return; } // Hide any Previous Errors XamlCodeEditor.ClearErrors(); // Try and Render Xaml to a UIElement UIElement element = null; try { element = _xamlRenderer.Render(text); } catch (Exception ex) { ShowExceptionNotification(ex); } if (element != null) { // Add element to main panel or sub-panel FrameworkElement root = null; if (CurrentSample.HasType) { root = SamplePage?.FindDescendant("XamlRoot"); if (root is Panel) { // If we've defined a 'XamlRoot' element to host us as a panel, use that. (root as Panel).Children.Clear(); (root as Panel).Children.Add(element); } else if (SamplePage != null) // UNO TODO { // if we didn't find a XamlRoot host, then we replace the entire content of // the provided sample page with the XAML. SamplePage.Content = element; } } else { // Otherwise, just replace our entire presenter's content SampleContent.Content = element; } // Tell the page we've finished with an update to the XAML contents, after the control has rendered. if (element is FrameworkElement fe) { fe.Loaded += XamlFrameworkElement_Loaded; // UNO TODO Console.WriteLine($"UpdateXamlRenderAsync attach loaded fe.IsLoaded:{fe.IsLoaded}"); if (fe.IsLoaded) { XamlFrameworkElement_Loaded(fe, new RoutedEventArgs()); } } } else if (_xamlRenderer.Errors.Count > 0) { var error = _xamlRenderer.Errors.First(); XamlCodeEditor.ReportError(error); } }