コード例 #1
0
        public CustomControlSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            // Add a DelegateGraphicsScreen as the first graphics screen to the graphics
            // service. This lets us do the rendering in the Render method of this class.
            var graphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };

            GraphicsService.Screens.Insert(0, graphicsScreen);

            // Create a theme. A theme defines the images of the controls and the default values of
            // the UI control properties.
            Theme theme = ContentManager.Load <Theme>("UI Themes/BlendBlue/Theme");

            // Create a renderer that uses the theme information. We do not use the default UIRenderer
            // class, instead we use our own MyUIRenderer that adds rendering of tree view items.
            var renderer = new MyUIRenderer(Game, theme);

            // Create the screen. A screen is the root of the UI control hierarchy.
            _uiScreen = new UIScreen("SampleUIScreen", renderer);

            // Screens must be added to the UI service to be updated each frame.
            UIService.Screens.Add(_uiScreen);

            // Add a tree view control to the screen.
            var padding  = new Vector4(0, 2, 4, 2);
            var treeView = new TreeView
            {
                X     = 10,
                Y     = 60,
                Items =
                {
                    new TreeViewItem
                    {
                        Header = new TextBlock{
                            Text = "Item 1", Padding = padding,
                        },
                        UserData = "1",
                    },
                    new TreeViewItem
                    {
                        Header = new TextBlock{
                            Text = "Item 2", Padding = padding,
                        },
                        UserData = "2",
                        Items    =
                        {
                            new TreeViewItem
                            {
                                Header = new TextBlock{
                                    Text = "Item 2.1", Padding = padding,
                                },
                                UserData = "2.1",
                            },
                            new TreeViewItem
                            {
                                Header = new TextBlock{
                                    Text = "Item 2.2", Padding = padding,
                                },
                                UserData = "2.2",
                                Items    =
                                {
                                    new TreeViewItem
                                    {
                                        Header = new TextBlock{
                                            Text = "Item 2.2.1", Padding = padding,
                                        },
                                        UserData = "2.2.1",
                                    },
                                    new TreeViewItem
                                    {
                                        Header = new TextBlock{
                                            Text = "Item 2.2.2", Padding = padding,
                                        },
                                        UserData = "2.2.2",
                                    },
                                }
                            },
                            new TreeViewItem
                            {
                                Header = new TextBlock{
                                    Text = "Item 2.3", Padding = padding,
                                },
                                UserData = "2.3",
                            },
                        }
                    },
                    new TreeViewItem
                    {
                        Header = new TextBlock{
                            Text = "Item 3 (The quick brown fox jumps over the lazy dog.)", Padding = padding,
                        },
                        UserData = "3",
                        Items    =
                        {
                            new TreeViewItem
                            {
                                Header = new TextBlock{
                                    Text = "Item 3.1", Padding = padding,
                                },
                                UserData = "3.1",
                            },
                            new TreeViewItem
                            {
                                Header = new TextBlock{
                                    Text = "Item 3.2", Padding = padding,
                                },
                                UserData = "3.2",
                            },
                            new TreeViewItem
                            {
                                Header = new Image{
                                    Texture = theme.Textures["UITexture"].Texture, SourceRectangle = new Rectangle(214, 66, 16, 16), Padding = padding,
                                },
                                UserData = "3.3",
                            },
                            new TreeViewItem
                            {
                                Header = new TextBlock{
                                    Text = "Item 3.4", Padding = padding,
                                },
                                UserData = "3.4",
                            },
                        }
                    },
                }
            };

            _uiScreen.Children.Add(treeView);

            // Handle InputProcessed events.
            treeView.InputProcessed += OnTreeViewInputProcessed;
        }
コード例 #2
0
    public CustomControlSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      // Add a DelegateGraphicsScreen as the first graphics screen to the graphics
      // service. This lets us do the rendering in the Render method of this class.
      var graphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, graphicsScreen);

      // Create a theme. A theme defines the images of the controls and the default values of 
      // the UI control properties.
      Theme theme = ContentManager.Load<Theme>("UI Themes/BlendBlue/Theme");

      // Create a renderer that uses the theme information. We do not use the default UIRenderer
      // class, instead we use our own MyUIRenderer that adds rendering of tree view items.
      var renderer = new MyUIRenderer(Game, theme);

      // Create the screen. A screen is the root of the UI control hierarchy.
      _uiScreen = new UIScreen("SampleUIScreen", renderer);

      // Screens must be added to the UI service to be updated each frame.
      UIService.Screens.Add(_uiScreen);

      // Add a tree view control to the screen.
      var padding = new Vector4F(0, 2, 4, 2);
      var treeView = new TreeView
      {
        X = 10,
        Y = 60,
        Items =
          {
            new TreeViewItem
            {
              Header = new TextBlock { Text = "Item 1", Padding = padding, },
              UserData = "1",
            },
            new TreeViewItem
            {
              Header = new TextBlock { Text = "Item 2", Padding = padding, },
              UserData = "2",
              Items =
              {
                new TreeViewItem
                {
                  Header = new TextBlock { Text = "Item 2.1", Padding = padding, },
                  UserData = "2.1",
                },
                new TreeViewItem
                {
                  Header = new TextBlock { Text = "Item 2.2", Padding = padding, },
                  UserData = "2.2",
                  Items =
                  {
                    new TreeViewItem
                    {
                      Header = new TextBlock { Text = "Item 2.2.1", Padding = padding, },
                      UserData = "2.2.1",
                    },
                    new TreeViewItem
                    {
                      Header = new TextBlock { Text = "Item 2.2.2", Padding = padding, },
                      UserData = "2.2.2",
                    },
                  }
                },
                new TreeViewItem
                {
                  Header = new TextBlock { Text = "Item 2.3", Padding = padding, },
                  UserData = "2.3",
                },
              }
            },
            new TreeViewItem
            {
              Header = new TextBlock { Text = "Item 3 (The quick brown fox jumps over the lazy dog.)", Padding = padding, },
              UserData = "3",
              Items =
              {
                new TreeViewItem
                {
                  Header = new TextBlock { Text = "Item 3.1", Padding = padding, },
                  UserData = "3.1",
                },
                new TreeViewItem
                {
                  Header = new TextBlock { Text = "Item 3.2", Padding = padding, },
                  UserData = "3.2",
                },
                new TreeViewItem
                {
                  Header = new Image { Texture = theme.Textures["UITexture"].Texture, SourceRectangle = new Rectangle(214, 66, 16, 16), Padding = padding, },
                  UserData = "3.3",
                },
                new TreeViewItem
                {
                  Header = new TextBlock { Text = "Item 3.4", Padding = padding, },
                  UserData = "3.4",
                },
              }
            },
          }
      };
      _uiScreen.Children.Add(treeView);

      // Handle InputProcessed events.
      treeView.InputProcessed += OnTreeViewInputProcessed;
    }