コード例 #1
0
        public void TestAuto()
        {
            var converter = new GridLengthTypeConverter();

            Assert.AreEqual(GridLength.Auto, converter.ConvertFromInvariantString("auto"));
            Assert.AreEqual(GridLength.Auto, converter.ConvertFromInvariantString(" AuTo "));
        }
コード例 #2
0
        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*"));
        }
コード例 #3
0
		public void TestAuto ()
		{
			var converter = new GridLengthTypeConverter ();

			Assert.AreEqual (GridLength.Auto, converter.ConvertFromInvariantString ("auto"));
			Assert.AreEqual (GridLength.Auto, converter.ConvertFromInvariantString (" AuTo "));
		}
コード例 #4
0
		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*"));

		}
コード例 #5
0
		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"));
		}
コード例 #6
0
        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"));
        }
コード例 #7
0
 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);
     }
 }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
0
        public void TestValueStar()
        {
            var converter = new GridLengthTypeConverter();

            Assert.AreEqual(new GridLength(32.3, GridUnitType.Star), converter.ConvertFromInvariantString("32.3*"));
        }
コード例 #14
0
        public void TestValue()
        {
            var converter = new GridLengthTypeConverter();

            Assert.AreEqual(new GridLength(3.3), converter.ConvertFromInvariantString("3.3"));
        }
コード例 #15
0
		public void TestValue ()
		{
			var converter = new GridLengthTypeConverter ();
			Assert.AreEqual (new GridLength(3.3), converter.ConvertFromInvariantString("3.3"));
		}
コード例 #16
0
		public void TestValueStar ()
		{
			var converter = new GridLengthTypeConverter ();
			Assert.AreEqual (new GridLength(32.3, GridUnitType.Star), converter.ConvertFromInvariantString("32.3*"));
		}
コード例 #17
0
 public override object ConvertFrom(object o)
 {
     return(_converter.ConvertFromInvariantString(o as string));
 }