Beispiel #1
0
        public void TestAuto()
        {
            var converter = new GridLengthTypeConverter();

            Assert.AreEqual(GridLength.Auto, converter.ConvertFromInvariantString("auto"));
            Assert.AreEqual(GridLength.Auto, converter.ConvertFromInvariantString(" AuTo "));
        }
		public void TestAuto ()
		{
			var converter = new GridLengthTypeConverter ();

			Assert.AreEqual (GridLength.Auto, converter.ConvertFromInvariantString ("auto"));
			Assert.AreEqual (GridLength.Auto, converter.ConvertFromInvariantString (" AuTo "));
		}
Beispiel #3
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*"));
        }
Beispiel #4
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);
            }
        }
		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"));
		}
Beispiel #7
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"));
        }
Beispiel #8
0
        //used to hide the Summary panel in portrait view. I don't bother checking for screen dimensions before doing this
        //since the button is hidden by the page resize code when the window is too small
        private void buttonHideSummary_Clicked(object sender, EventArgs e)
        {
            var converter = new GridLengthTypeConverter();

            // if it's star then the area is expanded and we should collapse it
            if (mainGrid.RowDefinitions[3].Height.IsStar)
            {
                mainGrid.RowDefinitions[3].Height = new GridLength(0);
                buttonHideSummary.Text            = "Open";
            }
            else
            {
                mainGrid.RowDefinitions[3].Height = new GridLength(3, GridUnitType.Star);
                buttonHideSummary.Text            = "Close";
            }
        }
        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);
        }
        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);
            }
        }
Beispiel #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);
            }
        }
Beispiel #13
0
        public void TestValueStar()
        {
            var converter = new GridLengthTypeConverter();

            Assert.AreEqual(new GridLength(32.3, GridUnitType.Star), converter.ConvertFromInvariantString("32.3*"));
        }
Beispiel #14
0
        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*"));
		}
Beispiel #17
0
 public XamlGridLengthTypeConverter()
 {
     _converter = new GridLengthTypeConverter();
 }