Inheritance: UIElement
Ejemplo n.º 1
0
        protected override void LoadContent()
        {
            var spriteBatchAdapter = new SpriteBatchAdapter(new SpriteBatch(this.GraphicsDevice));
            var spriteFontAdapter = new SpriteFontAdapter(this.Game.Content.Load<SpriteFont>("SpriteFont"));
            var renderer = new Renderer(spriteBatchAdapter, new PrimitivesService(this.GraphicsDevice));
            this.rootElement = new RootElement(this.GraphicsDevice.Viewport.ToRect(), renderer, new InputManager());

            // Setup Layout
            var cardImage = new Image { Stretch = Stretch.None };

            var cardToggleButton = new ToggleButton
                {
                    Content = cardImage,
                    Margin = new Thickness(10)
                };

            var resetButton = new Button
                {
                    Content =
                        new Border
                            {
                                Background = new SolidColorBrush(Colors.LightGray), 
                                Child = new TextBlock(spriteFontAdapter)
                                    {
                                        Text = "Reset",
                                        Margin = new Thickness(10)
                                    }
                            }, 
                    Margin = new Thickness(10), 
                    HorizontalAlignment = HorizontalAlignment.Center
                };

            var stackPanel = new StackPanel
                {
                    Children =
                        {
                            cardToggleButton,
                            resetButton
                        }
                };

            this.rootElement.Content = stackPanel;

            // Setup Data Binding
            var faceDownImage = new TextureImage(new Texture2DAdapter(this.Game.Content.Load<Texture2D>("FaceDown")));
            var faceUpImage = new TextureImage(new Texture2DAdapter(this.Game.Content.Load<Texture2D>("FaceUp")));

            var card = new Card(faceDownImage, faceUpImage);

            cardImage.Bind(
                Image.SourceProperty,
                card.CardImage);

            cardToggleButton.Bind(
                ToggleButton.IsCheckedProperty,
                card.IsCardFaceUp,
                card.IsCardFaceUp);

            resetButton.Click += (sender, args) => card.Reset();
        }
Ejemplo n.º 2
0
        private void BuildNinePatch(string name)
        {
            var c1 = new Image
            {
                Source = new TextureImage(new Texture2DAdapter(content.Load<Texture2D>(@"UI/c1"))),
                Stretch = Stretch.Fill
            };
            Grid.SetColumn(c1, 0);
            Grid.SetRow(c1, 0);
            this.Children.Add(c1);
            var c2 = new Image
            {
                Source = new TextureImage(new Texture2DAdapter(content.Load<Texture2D>(@"UI/c2"))),
                Stretch = Stretch.Fill
            };
            Grid.SetColumn(c2, 2);
            Grid.SetRow(c2, 0);
            this.Children.Add(c2);
            var c3 = new Button()
            {
                Content = new Grid() { }
            }; 
            c3.Content = new Image
            {
                Source = new TextureImage(new Texture2DAdapter(content.Load<Texture2D>(@"UI/c3"))),
                Stretch = Stretch.Fill
            };
            c3.Click += (sender, args) => { this.isReasizeClicked = !this.isReasizeClicked; };
            Grid.SetColumn(c3, 2);
            Grid.SetRow(c3, 2);
            this.Children.Add(c3);
            var c4 = new Image
            {
                Source = new TextureImage(new Texture2DAdapter(content.Load<Texture2D>(@"UI/c4"))),
                Stretch = Stretch.Fill
            };
            Grid.SetColumn(c4, 0);
            Grid.SetRow(c4, 2);
            this.Children.Add(c4);

            var e1 = new Image
            {
                Source = new TextureImage(new Texture2DAdapter(content.Load<Texture2D>(@"UI/e1"))),
                Stretch = Stretch.Fill
            };
            Grid.SetColumn(e1, 0);
            Grid.SetRow(e1, 1);
            this.Children.Add(e1);
            var e2 = new Button()
                         {
                             Content = new Grid() {}
                         };
            ((Grid)e2.Content).Children.Add(new Image
            {
                Source = new TextureImage(new Texture2DAdapter(content.Load<Texture2D>(@"UI/e2"))),
                Stretch = Stretch.Fill
            });
            ((Grid)e2.Content).Children.Add(new TextBlock(font)
                                                {
                                                    Text = "[" + name + "]",
                                                    Foreground = new SolidColorBrush(Colors.White),
                                                    Margin = new Thickness(0,2),
                                                    HorizontalAlignment = HorizontalAlignment.Center
                                                });
            e2.Click += (sender, args) => { this.isHeaderClicked = !this.isHeaderClicked; };
            Grid.SetColumn(e2, 1);
            Grid.SetRow(e2, 0);
            this.Children.Add(e2);
            var e3 = new Image
            {
                Source = new TextureImage(new Texture2DAdapter(content.Load<Texture2D>(@"UI/e3"))),
                Stretch = Stretch.Fill
            };
            Grid.SetColumn(e3, 2);
            Grid.SetRow(e3, 1);
            this.Children.Add(e3);
            var e4 = new Image
            {
                Source = new TextureImage(new Texture2DAdapter(content.Load<Texture2D>(@"UI/e4"))),
                Stretch = Stretch.Fill
            };
            Grid.SetColumn(e4, 1);
            Grid.SetRow(e4, 2);
            this.Children.Add(e4);
            var m = new Image
            {
                Source = new TextureImage(new Texture2DAdapter(content.Load<Texture2D>(@"UI/m"))),
                Stretch = Stretch.Fill
            };
            Grid.SetColumn(m, 1);
            Grid.SetRow(m, 1);
            this.Children.Add(m);
        }