public void TestAuto() { var converter = new GridLengthTypeConverter(); Assert.AreEqual(GridLength.Auto, converter.ConvertFromInvariantString("auto")); Assert.AreEqual(GridLength.Auto, converter.ConvertFromInvariantString(" AuTo ")); }
public void TestStar() { var converter = new GridLengthTypeConverter(); Assert.AreEqual(new GridLength(1, GridUnitType.Star), converter.ConvertFromInvariantString("*")); Assert.AreEqual(new GridLength(42, GridUnitType.Star), converter.ConvertFromInvariantString("42*")); }
public void TestAuto () { var converter = new GridLengthTypeConverter (); Assert.AreEqual (GridLength.Auto, converter.ConvertFromInvariantString ("auto")); Assert.AreEqual (GridLength.Auto, converter.ConvertFromInvariantString (" AuTo ")); }
public void TestStar () { var converter = new GridLengthTypeConverter (); Assert.AreEqual (new GridLength (1, GridUnitType.Star), converter.ConvertFromInvariantString ("*")); Assert.AreEqual (new GridLength (42, GridUnitType.Star), converter.ConvertFromInvariantString ("42*")); }
public void TestAbsolute () { var converter = new GridLengthTypeConverter (); Assert.AreEqual (new GridLength (42), converter.ConvertFromInvariantString ("42")); Assert.AreEqual (new GridLength (42.2), converter.ConvertFromInvariantString ("42.2")); Assert.Throws<FormatException> (() => converter.ConvertFromInvariantString ("foo")); }
public void TestAbsolute() { var converter = new GridLengthTypeConverter(); Assert.AreEqual(new GridLength(42), converter.ConvertFromInvariantString("42")); Assert.AreEqual(new GridLength(42.2), converter.ConvertFromInvariantString("42.2")); Assert.Throws <FormatException>(() => converter.ConvertFromInvariantString("foo")); }
public static void SetRowDefinitions(this Grid grid, params string[] lens) { grid.RowDefinitions.Clear(); foreach (var len in lens) { var rowDefinition = new RowDefinition(); rowDefinition.Height = (GridLength)gridLengthTypeConverter.ConvertFromInvariantString(len); grid.RowDefinitions.Add(rowDefinition); } }
public object ProvideValue(IServiceProvider serviceProvider) { if (s_layoutService == null) { s_layoutService = DependencyService.Get <ILayoutService>(); } if (s_layoutService == null) { System.Diagnostics.Debug.WriteLine("ScaledGridLength has no ILayoutService!"); var tc = new GridLengthTypeConverter(); return(tc.ConvertFromInvariantString(Length)); } if (Length == "*") { return(GridLength.Star); } else if (Length == "Auto") { return(GridLength.Auto); } else { double d; if (double.TryParse(Length, out d)) { return(new GridLength(s_layoutService.GetScaledDouble(d))); } throw new Exception("Unable to convert to GridLength: " + Length); } }
public RxGrid(string rows, string columns) { var converter = new GridLengthTypeConverter(); foreach (var rowDefinition in rows.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(_ => (GridLength)converter.ConvertFromInvariantString(_)) .Select(_ => new RowDefinition() { Height = _ })) { RowDefinitions.Add(rowDefinition); } foreach (var columnDefinition in columns.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(_ => (GridLength)converter.ConvertFromInvariantString(_)) .Select(_ => new ColumnDefinition() { Width = _ })) { ColumnDefinitions.Add(columnDefinition); } }
List <IGridRowDefinition> CreateTestRows(params string[] rowHeights) { var converter = new GridLengthTypeConverter(); var rowDefs = new List <IGridRowDefinition>(); foreach (var height in rowHeights) { var gridLength = converter.ConvertFromInvariantString(height); var rowDef = Substitute.For <IGridRowDefinition>(); rowDef.Height.Returns(gridLength); rowDefs.Add(rowDef); } return(rowDefs); }
List <IGridColumnDefinition> CreateTestColumns(params string[] columnWidths) { var converter = new GridLengthTypeConverter(); var colDefs = new List <IGridColumnDefinition>(); foreach (var width in columnWidths) { var gridLength = converter.ConvertFromInvariantString(width); var colDef = Substitute.For <IGridColumnDefinition>(); colDef.Width.Returns(gridLength); colDefs.Add(colDef); } return(colDefs); }
private void AddLayout(LayoutTemplate layoutTemplate, Layout <View> parentLayout) { Layout <View> newLayout = null; ScrollView scrollView = null; if (layoutTemplate.ScrollX || layoutTemplate.ScrollY) { scrollView = new ScrollView(); AttributeHelper.ApplyTranslation(scrollView, layoutTemplate.Attributes); if (layoutTemplate.ScrollX && layoutTemplate.ScrollY) { scrollView.Orientation = ScrollOrientation.Both; } else if (layoutTemplate.ScrollY) { scrollView.Orientation = ScrollOrientation.Vertical; } else if (layoutTemplate.ScrollX) { scrollView.Orientation = ScrollOrientation.Horizontal; } if (parentLayout is Grid) { try { (( Grid )parentLayout).Children.Add( newLayout, layoutTemplate.Column, layoutTemplate.Row ); Grid.SetColumnSpan(newLayout, layoutTemplate.ColumnSpan); Grid.SetRowSpan(newLayout, layoutTemplate.RowSpan); } catch { } } else { parentLayout.Children.Add(scrollView); } } if (layoutTemplate.Type == "StackLayout") { var sl = new StackLayout(); sl.Orientation = layoutTemplate.Orientation; if (layoutTemplate.Spacing >= 0) { sl.Spacing = layoutTemplate.Spacing; } newLayout = sl; } else if (layoutTemplate.Type == "Grid") { var g = new Grid(); if (layoutTemplate.Spacing >= 0) { g.RowSpacing = layoutTemplate.Spacing; g.ColumnSpacing = layoutTemplate.Spacing; } var gridConverter = new GridLengthTypeConverter(); var rowDefinitions = layoutTemplate.RowDefinitions.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var def in rowDefinitions) { var gridLength = ( GridLength )gridConverter.ConvertFromInvariantString(def); g.RowDefinitions.Add(new RowDefinition { Height = gridLength }); } var columnDefinitions = layoutTemplate.ColumnDefinitions.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var def in columnDefinitions) { var gridLength = ( GridLength )gridConverter.ConvertFromInvariantString(def); g.ColumnDefinitions.Add(new ColumnDefinition { Width = gridLength }); } newLayout = g; } if (newLayout == null) { return; } if (scrollView != null) { scrollView.Content = newLayout; } else { if (parentLayout is Grid) { try { (( Grid )parentLayout).Children.Add( newLayout, layoutTemplate.Column, layoutTemplate.Row ); Grid.SetColumnSpan(newLayout, layoutTemplate.ColumnSpan); Grid.SetRowSpan(newLayout, layoutTemplate.RowSpan); } catch { } } else { parentLayout.Children.Add(newLayout); } } layouts.Add(layoutTemplate.Name.ToLower(), newLayout); AttributeHelper.ApplyTranslation(newLayout, layoutTemplate.Attributes); foreach (var child in layoutTemplate.Children) { AddLayout(child, newLayout); } }
public void TestValueStar() { var converter = new GridLengthTypeConverter(); Assert.AreEqual(new GridLength(32.3, GridUnitType.Star), converter.ConvertFromInvariantString("32.3*")); }
public void TestValue() { var converter = new GridLengthTypeConverter(); Assert.AreEqual(new GridLength(3.3), converter.ConvertFromInvariantString("3.3")); }
public void TestValue () { var converter = new GridLengthTypeConverter (); Assert.AreEqual (new GridLength(3.3), converter.ConvertFromInvariantString("3.3")); }
public void TestValueStar () { var converter = new GridLengthTypeConverter (); Assert.AreEqual (new GridLength(32.3, GridUnitType.Star), converter.ConvertFromInvariantString("32.3*")); }
public override object ConvertFrom(object o) { return(_converter.ConvertFromInvariantString(o as string)); }