Inheritance: Panel
示例#1
0
        public NinePatch(ContentManager content, Canvas canvas, string name, SpriteFontAdapter font)
        {
            this.RowDefinitions.Add(new RowDefinition { Height = new GridLength(16)});
            this.RowDefinitions.Add(new RowDefinition());
            this.RowDefinitions.Add(new RowDefinition {Height = new GridLength(16)});
            this.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(16)});
            this.ColumnDefinitions.Add(new ColumnDefinition());
            this.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(6)});

            this.content = content;
            this.canvas = canvas;

            this.font = font;

            BuildNinePatch(name);
        }
示例#2
0
文件: Game1.cs 项目: redbadger/XPF
        /// <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;
        }