public void MarkupDefinedSwipeItemDoesNotCrash() { if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone3)) { Log.Warning("Test is disabled pre RS3."); return; } Windows.UI.Xaml.Controls.Grid rootGrid; RunOnUIThread.Execute(() => { rootGrid = (Windows.UI.Xaml.Controls.Grid)XamlReader.LoadWithInitialTemplateValidation( "<Grid xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> " + "<GridView> " + "<GridViewItem> " + "<SwipeControl> " + "<SwipeControl.RightItems> " + "<SwipeItems> " + "<SwipeItem " + "Background='#E81123' " + "Foreground='White' " + "Text='Remove'/> " + "</SwipeItems> " + "</SwipeControl.RightItems> " + "<Grid Width='200' Height='200' Background='green'/> " + "</SwipeControl> " + "</GridViewItem> " + "</GridView> " + "</Grid>"); MUXControlsTestApp.App.TestContentRoot = rootGrid; }); IdleSynchronizer.Wait(); }
public ViewModelHubSection(Type contentControlType, string header = "", bool isHeaderInteractive = false) { this.Header = header; this.IsHeaderInteractive = isHeaderInteractive; string sectionXaml = String.Format(XamlTemplate, contentControlType.Namespace, contentControlType.Name); object style = null; Application.Current.Resources.TryGetValue(typeof(HubSection), out style); var hubSectionStyle = style as Style; if (hubSectionStyle != null) { this.Style = hubSectionStyle; } this.ContentTemplate = (DataTemplate)XamlReader.LoadWithInitialTemplateValidation(sectionXaml); this.Loaded += HubSection_Loaded; }
public UIElement Render(string content) { Errors.Clear(); if (string.IsNullOrWhiteSpace(content)) { // Nothing to do! return(null); } // TODO: add flag about using pre-parsing or not. // Pre-parse if (!content.Contains("xmlns")) { // Find the end of the first tag var oti = content.IndexOf(">"); if (oti != -1) { content = content.Substring(0, oti) + @" xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""" + content.Substring(oti); } } // Attempt Render UIElement element = null; try { var obj = XamlReader.LoadWithInitialTemplateValidation(content); // TODO: Add Flag to change which function to use. if (!(obj is UIElement)) { throw new NotSupportedException("Content must be a UIElement."); } element = obj as UIElement; } catch (Exception e) { // Highlight Error (we'll only get one at a time). string msg = e.Message; msg = msg.Replace("The text associated with this error code could not be found.", string.Empty).Trim(); uint line = 1; uint column = 1; // No default namespace has been declared. [Line: 1 Position: 2] int il = msg.IndexOf("Line: "); if (il >= 0) { line = uint.Parse(msg.Substring(il + 6, msg.IndexOf("P", il) - il - 7)); } int pl = msg.IndexOf("Position: "); if (pl >= 0) { column = uint.Parse(msg.Substring(pl + 9, msg.IndexOf("]", pl) - pl - 9)); } // TODO: Should I just throw this nicely parsed message? Errors.Add(new XamlExceptionRange(msg, e, line, column, line, column + 8)); // TODO: Inspect Content at this position and go until space / EOL } // Set DataContext to root element or to provided DataContext (if it exists). // May get overwritten by d:DesignData loading later. if (element is FrameworkElement) { var fwe = element as FrameworkElement; fwe.DataContext = this.DataContext == null ? element : this.DataContext; } return(element); }