ItemsControl allows you to represent a collection of items and provides scaffolding to generate the UI for each item.
Inheritance: Control
Beispiel #1
0
        protected override void LoadContent()
        {
            this.spriteFontAdapter = new SpriteFontAdapter(this.Game.Content.Load<SpriteFont>("SpriteFont"));
            this.spriteBatchAdapter = new SpriteBatchAdapter(new SpriteBatch(this.GraphicsDevice));

            var renderer = new Renderer(this.spriteBatchAdapter, new PrimitivesService(this.GraphicsDevice));

            this.rootElement = new RootElement(this.GraphicsDevice.Viewport.ToRect(), renderer, new InputManager());

            var itemsControl = new ItemsControl();

            // this.rootElement.Content = itemsControl;
        }
Beispiel #2
0
        protected override void LoadContent()
        {
            this.spriteBatchAdapter = new SpriteBatchAdapter(new SpriteBatch(this.GraphicsDevice));
            var primitivesService = new PrimitivesService(this.GraphicsDevice);
            var renderer = new Renderer(this.spriteBatchAdapter, primitivesService);

            var spriteFontAdapter = new SpriteFontAdapter(this.Game.Content.Load<SpriteFont>("Segoe18"));
            var largeFont = new SpriteFontAdapter(this.Game.Content.Load<SpriteFont>("Segoe30"));

            var addButtonImageTexture =
                new TextureImage(new Texture2DAdapter(this.Game.Content.Load<Texture2D>("AddButton")));
            var trashButtonImageTexture =
                new TextureImage(new Texture2DAdapter(this.Game.Content.Load<Texture2D>("TrashButton")));

            this.rootElement = new RootElement(this.GraphicsDevice.Viewport.ToRect(), renderer, new InputManager());

            var buttonClickResults = new ObservableCollection<string>();

            var header1 = new TextBlock(spriteFontAdapter)
                {
                    Text = "MY APPLICATION", 
                    Foreground = new SolidColorBrush(Colors.White), 
                    Margin = new Thickness(10)
                };
            var header2 = new TextBlock(largeFont)
                {
                    Text = "XNA Application Bar", 
                    Foreground = new SolidColorBrush(Colors.White), 
                    Margin = new Thickness(10)
                };
            var itemsControl = new ItemsControl
                {
                    ItemsSource = buttonClickResults,
                    ItemTemplate = _ =>
                        {
                            var textBlock = new TextBlock(spriteFontAdapter)
                                {
                                    Foreground = new SolidColorBrush(Colors.White) 
                                };
                            textBlock.Bind(
                                TextBlock.TextProperty, BindingFactory.CreateOneWay<string>());
                            return textBlock;
                        }
                };

            var scrollViewer = new ScrollViewer { Content = itemsControl };

            var applicationBar = new ApplicationBar
                {
                    Buttons =
                        {
                            new ApplicationBarIconButton("Add", addButtonImageTexture), 
                            new ApplicationBarIconButton("Delete", trashButtonImageTexture)
                        }
                };

            var grid = new Grid
                {
                    Background = new SolidColorBrush(Colors.Black), 
                    RowDefinitions =
                        {
                            new RowDefinition { Height = GridLength.Auto }, 
                            new RowDefinition { Height = GridLength.Auto }, 
                            new RowDefinition(), 
                            new RowDefinition { Height = new GridLength(70) }
                        }, 
                    Children =
                        {
                            header1, 
                            header2, 
                            scrollViewer,
                            applicationBar
                        }
                };

            applicationBar.Clicks.Subscribe(
                Observer.Create<ApplicationBarIconButton>(s => buttonClickResults.Add(s.Text)));

            Grid.SetRow(header1, 0);
            Grid.SetRow(header2, 1);
            Grid.SetRow(scrollViewer, 2);
            Grid.SetRow(applicationBar, 3);

            this.rootElement.Content = grid;
        }
Beispiel #3
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;
        }
Beispiel #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;
        }
Beispiel #5
0
        protected override void LoadContent()
        {
            this.spriteFont = this.Game.Content.Load<SpriteFont>("SpriteFont");
            this.spriteBatchAdapter = new SpriteBatchAdapter(new SpriteBatch(this.GraphicsDevice));
            var spriteFontAdapter = new SpriteFontAdapter(this.spriteFont);

            var items = new ObservableCollection<string>();
            var itemsControl = new ItemsControl
                {
                    ItemTemplate = _ =>
                        {
                            var textBlock = new TextBlock(spriteFontAdapter)
                                {
                                    Margin = new Thickness(0, 0, 0, 50), 
                                    Background = new SolidColorBrush(GetRandomColor(this.random))
                                };
                            textBlock.Bind(TextBlock.TextProperty, BindingFactory.CreateOneWay<string>());
                            return textBlock;
                        }, 
                    ItemsSource = items
                };

            var renderer = new Renderer(this.spriteBatchAdapter, new PrimitivesService(this.GraphicsDevice));

            this.rootElement = new RootElement(this.GraphicsDevice.Viewport.ToRect(), renderer, new InputManager())
                {
                    Content = new ScrollViewer { Content = itemsControl }
                };

            Observable.Timer(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)).ObserveOnDispatcher().Subscribe(
                l => items.Add(DateTime.Now.ToString()));

            /*var renderer = new Renderer(this.spriteBatchAdapter, new PrimitivesService(this.GraphicsDevice));

            this.rootElement = new RootElement(this.GraphicsDevice.Viewport.ToRect(), renderer, new InputManager());

            var textBlock = new TextBlock(spriteFontAdapter)
                {
                    Text =
                        "Red Badger is a product and service consultancy, specialising in bespoke software projects, developer tools and platforms on the Microsoft technology stack.", 
                    Background = new SolidColorBrush(Colors.Red), 
                    HorizontalAlignment = HorizontalAlignment.Left, 
                    VerticalAlignment = VerticalAlignment.Top, 
                    Wrapping = TextWrapping.Wrap, 
                    Margin = new Thickness(10), 
                    Padding = new Thickness(10)
                };

            this.rootElement.Content = textBlock;

            var grid = new Grid { RowDefinitions = { new RowDefinition(), new RowDefinition() } };

            var button = new Button
                {
                    Content =
                        new TextBlock(spriteFontAdapter)
                            {
                               Text = "Click", Background = new SolidColorBrush(Colors.Blue) 
                            }
                };
            grid.Children.Add(button);
            Grid.SetRow(button, 1);

            this.textBlock = new TextBlock(spriteFontAdapter) { Text = "Item 1", Margin = new Thickness(15) };
            this.stackPanel = new StackPanel
                {
                    Children =
                        {
                            this.textBlock, 
                            new TextBlock(spriteFontAdapter) { Text = "Item 2", Margin = new Thickness(15) }, 
                            new TextBlock(spriteFontAdapter) { Text = "Item 3", Margin = new Thickness(15) }
                        }
                };
            grid.Children.Add(this.stackPanel);
            this.rootElement.Content = grid;

            button.Click += (sender, args) => this.stackPanel.Children.RemoveAt(0);*/
        }