Inheritance: RedBadger.Xpf.Controls.Primitives.ButtonBase
Exemplo n.º 1
0
        public override void OnApplyTemplate()
        {
            if (this.buttons.Count > 4)
            {
                throw new NotSupportedException("Too many buttons - the maximum is 4.");
            }

            this.Height = 70;

            var containingBorder = new Border { Background = new SolidColorBrush(new Color(31, 31, 31, 255)) };

            var itemsControl = new ItemsControl
                {
                    ItemsPanel = new StackPanel { Orientation = Orientation.Horizontal }, 
                    ItemsSource = this.buttons,
                    ItemTemplate = dataContext =>
                        {
                            var image = new Image { Stretch = Stretch.None };
                            image.Bind(
                                Image.SourceProperty, 
                                BindingFactory.CreateOneWay<ApplicationBarIconButton, ImageSource>(
                                    iconButton => iconButton.IconImageSource));

                            var button = new Button { Content = image, Margin = new Thickness(18, 0, 18, 0) };

							//Observable.FromEvent<EventArgs>(
							//    handler => button.Click += handler,
							//    handler => button.Click -= handler).Select(
							//        eventArgs => (ApplicationBarIconButton)((Button)eventArgs.Sender).DataContext).
							//    Subscribe(this.clicks);

                            return button;
                        }, 
                    HorizontalAlignment = HorizontalAlignment.Center
                };

            containingBorder.Child = itemsControl;

            this.Content = containingBorder;
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     LoadContent will be called once per game and is the place to load
        ///     all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            this.spriteBatch = new SpriteBatchAdapter(new SpriteBatch(this.GraphicsDevice));
            var primitiveService = new PrimitivesService(this.GraphicsDevice);
            var renderer = new Renderer(this.spriteBatch, primitiveService);
            var input = new InputManager();
            this.root = new RootElement(this.GraphicsDevice.Viewport.ToRect(), renderer, input);

            this.font = new SpriteFontAdapter(this.Content.Load<SpriteFont>(@"SpriteFont"));
            this.chunks = new ObservableCollection<Chunk>();

            string[] files = Directory.GetFiles(Environment.CurrentDirectory + @"\Content\Textures");

            foreach (string file in files)
            {
                var chunk = new Chunk
                    {
                        Name = Path.GetFileNameWithoutExtension(file), 
                        Texture = this.Content.Load<Texture2D>(@"Textures/" + Path.GetFileNameWithoutExtension(file))
                    };
                this.chunks.Add(chunk);
            }

            var items = new ItemsControl
                {
                    ItemTemplate = _ =>
                        {
                            var textBlock = new TextBlock(this.font) { Foreground = new SolidColorBrush(Colors.White), HorizontalAlignment = HorizontalAlignment.Center };
                            textBlock.Bind(
                                TextBlock.TextProperty, BindingFactory.CreateOneWay<Chunk, string>(o => o.Name));

                            var image = new Image { Stretch = Stretch.Fill, Width = 100, };
                            image.Bind(
                                Image.SourceProperty, BindingFactory.CreateOneWay<Chunk, ImageSource>(o => o.XnaImage));
                            
                            var panel = new StackPanel
                                {
                                    Orientation = Orientation.Vertical, 
                                    Background = new SolidColorBrush(new Media.Color(0, 0, 0, 100)), 
                                };

                            panel.Children.Add(image);
                            panel.Children.Add(textBlock);

                            var border = new Border
                                {
                                    BorderBrush = new SolidColorBrush(Colors.Black), 
                                    BorderThickness = new Thickness(2, 2, 2, 2), 
                                    Margin = new Thickness(5, 5, 5, 5), 
                                    Child = panel, 
                                };

                            var button = new Button { Content = border, Margin = new Thickness(5, 5, 5, 5), };

                            return button;
                        }, 
                    ItemsSource = this.chunks, 
                };

            items.ItemsPanel.Margin = new Thickness(0, 0, 25, 0);

            var scrollViewer = new ScrollViewer { Content = items };

            var canvas = new Canvas { };

            var chunkPallet = new NinePatch(this.Content, canvas, "Chunk Pallet", this.font)
                {
                   Width = 280, Height = 550, 
                };
            this.ninePatches.Add(chunkPallet);

            chunkPallet.Children.Add(scrollViewer);
            canvas.Children.Add(chunkPallet);

            Grid.SetColumn(scrollViewer, 1);
            Grid.SetRow(scrollViewer, 1);

            Canvas.SetLeft(chunkPallet, 740);
            Canvas.SetTop(chunkPallet, 20);

            this.root.Content = canvas;
        }