Example #1
0
        /* index.OnClick */
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnClick(object sender, EventArgs args)
        {
            var label = new Label
            {
                Text = "abcde",
            };

            if ((x / 10) % 2 == 0)
            {
                //    CanvasAppend(label, x, 0, 50, 50);
            }
            else
            {
                //   CanvasAppend(label, 0, x, 50, 50);
            }

            var box = new MyBox
            {
                BackgroundColor = Color.Black,
            };

            CanvasAppend(box, 40, 40, 50, 50);

            x += 50;
            y += 50;
        }
Example #2
0
        public MainPage()
        {
            InitializeComponent();

            Label label = new Label
            {
                Text = "Hello Xamarin!!",
            };

            Label label2 = new Label
            {
                Text = "Hello Xamarin2!!",
            };

            // 追加方法1
            MainLayout.Children.Add(label,
                                    Constraint.RelativeToParent(parent => (parent.Width / 2) - (label.Width / 2)),
                                    Constraint.RelativeToParent(parent => (parent.Height / 2) - (label.Height / 2)),
                                    Constraint.RelativeToParent(parent => parent.Width),
                                    Constraint.Constant(50));

            // 追加方法2
            Expression <Func <Rectangle> > ex = () => new Rectangle(200, 200, 50, 50);

            MainLayout.Children.Add(label2, ex);

            var box = new MyBox
            {
                Color         = Color.Red,
                WidthRequest  = 50,
                HeightRequest = 50,
            };

            MainLayout.Children.Add(box, () => new Rectangle(50, 50, 50, 50));

            var list = new List <int>
            {
                10, 33, 123, 2, 1, 30,
            };

            var result = from x in list
                         where x % 2 == 0
                         orderby x descending
                         select x;

            label.Text = "";

            foreach (var s in result.ToArray())
            {
                label.Text += s + ", ";
            }
        }