protected override void OnLoad()
        {
            // size controls
            {
                var widthL = new TextBlock { Text = "Width:", VerticalAlignment = VerticalAlignment.Center };
                var widthTB = new TextBox { Text = "", VerticalAlignment = VerticalAlignment.Center };
                var widthSP = new StackPanel { Orientation = Orientation.Horizontal,
                    Margin = new Vector4F(4),
                    Padding = new Vector4F(4),
                };
                widthSP.Children.Add(widthL);
                widthSP.Children.Add(widthTB);

                var sizeStack = new StackPanel() { Orientation = Orientation.Vertical,
                    Margin = new Vector4F(4),
                    Padding = new Vector4F(4),
                };
                sizeStack.Children.Add(widthSP);
                
                var sizeGroup = new GroupBox()
                {
                    Title = "Size",
                    Content = sizeStack,
                    Margin = new Vector4F(4),
                    Padding = new Vector4F(4),
                };

                this.Content = sizeGroup;
            }

            base.OnLoad();
        }
Beispiel #2
0
    public DialogDemoWindow()
    {
      Title = "Dialog Demo";
      ClipContent = true;

      var button0 = new Button
      {
        Content = new TextBlock { Text = "Open dialog with layout from code", WrapText = true },
        Margin = new Vector4F(4),
      };
      button0.Click += OpenDialogFromCode;

      var button1 = new Button
      {
        Content = new TextBlock { Text = "Open dialog with layout from XML", WrapText = true },
        Margin = new Vector4F(4),
      };
      button1.Click += OpenDialogFromXml;

      var stackPanel = new StackPanel { Margin = new Vector4F(4) };
      stackPanel.Children.Add(button0);
      stackPanel.Children.Add(button1);

      Content = stackPanel;
    }
Beispiel #3
0
    public GameMenuWindow()
    {
      // Center the window on the screen.
      HorizontalAlignment = HorizontalAlignment.Center;
      VerticalAlignment = VerticalAlignment.Center;

      Title = "Game Paused";

      // Optional: If we want to hide the window close button, we can simply set its style to null.
      CloseButtonStyle = null;

      var resumeButton = new Button
      {
        Margin = new Vector4F(10),
        Width = 200,
        Height = 60,
        Content = new TextBlock { Text = "Resume" },

        // The Resume button is the "Default button" as well as the "Cancel button". (If the
        // user presses A or START and no one else handles the button presses then the default
        // button is invoked. If the user presses B or BACK and no one else handles the button 
        // presses then the Cancel button is invoked.)
        IsDefault = true,
        IsCancel = true,
      };
      resumeButton.Click += (s, e) => Close();

      var optionsButton = new Button
      {
        Margin = new Vector4F(10),
        Width = 200,
        Height = 60,
        Content = new TextBlock { Text = "Options" },
      };
      optionsButton.Click += (s, e) => new OptionsWindow().Show(this);

      var endGameButton = new Button
      {
        Margin = new Vector4F(10),
        Width = 200,
        Height = 60,
        Content = new TextBlock { Text = "Back to main menu" },
      };
      endGameButton.Click += (s, e) => DialogResult = false;

      var stackPanel = new StackPanel
      {
        HorizontalAlignment = HorizontalAlignment.Center,
        VerticalAlignment = VerticalAlignment.Center,
      };
      stackPanel.Children.Add(resumeButton);
      stackPanel.Children.Add(optionsButton);
      stackPanel.Children.Add(endGameButton);

      Content = stackPanel;
    }
        public ConsoleToolWindow(IConsoleCommandHost host, string methodOrPropertyName)
        {
            Height = 70;
            CanResize = true;
            Title = host.Name + "." + methodOrPropertyName;
            StackPanel = new StackPanel
                             {
                                 HorizontalAlignment = HorizontalAlignment.Stretch,
                                 VerticalAlignment = VerticalAlignment.Stretch
                             };

            Content = StackPanel;
        }
Beispiel #5
0
        public PauseWindow()
        {
            HorizontalAlignment = DigitalRune.Game.UI.HorizontalAlignment.Center;
            VerticalAlignment = DigitalRune.Game.UI.VerticalAlignment.Center;

            Title = "Game Paused";

            CloseButtonStyle = null;

            var resumeButton = new Button
            {
                Margin = new Vector4F(10),
                Width = 200,
                Height = 60,
                Content = new TextBlock {  Text = "Resume" },
                IsDefault = true,
                IsCancel = true,
            };
            resumeButton.Click += (s, e) => Close();

            var optionsButton = new Button
            {
                Margin = new Vector4F(10),
                Width = 200,
                Height = 60,
                Content = new TextBlock { Text = "Options" },
            };
            optionsButton.Click += (s, e) => new OptionsWindow().Show(this);

            var endGameButton = new Button
            {
                Margin = new Vector4F(10),
                Width = 200,
                Height = 60,
                Content = new TextBlock { Text = "Back to Main Menu" },
            };
            endGameButton.Click += (s, e) => DialogResult = false;

            var stackPanel = new StackPanel
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
            };

            stackPanel.Children.Add(resumeButton);
            stackPanel.Children.Add(optionsButton);
            stackPanel.Children.Add(endGameButton);

            Content = stackPanel;
        }
Beispiel #6
0
    private void OpenDialogFromCode(object sender, EventArgs eventArgs)
    {
      // ----- Create dialog.
      var text = new TextBlock
      {
        Text = "This layout was defined in code.",
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Center,
      };

      var button = new Button
      {
        Content = new TextBlock { Text = "Ok" },
        IsCancel = true,       // Cancel buttons are clicked when the user presses ESC (or BACK or B on the gamepad).
        IsDefault = true,      // Default buttons are clicked when the user presses ENTER or SPACE (or START or A on the gamepad).
        Margin = new Vector4F(4),
        Width = 60,
        HorizontalAlignment = HorizontalAlignment.Center,
      };

      var stackPanel = new StackPanel { Margin = new Vector4F(4) };
      stackPanel.Children.Add(text);
      stackPanel.Children.Add(button);

      var window = new Window
      {
        CanResize = false,
        IsModal = true,             // Modal dialogs consume all input until the window is closed.
        Content = stackPanel,
        MinHeight = 0,
        Title = "A modal dialog from code",
      };

      button.Click += (s, e) => window.Close();

      // ----- Show the window in the center of the screen.
      // First, we need to open the window. 
      window.Show(this);

      // The window is now part of the visual tree of controls and can be measured. (The 
      // window does not have a fixed size. Window.Width and Window.Height are NaN. The 
      // size is calculated automatically depending on its content.)
      window.Measure(new Vector2F(float.PositiveInfinity));

      // Measure computes DesiredWidth and DesiredHeight. With this info we can center the 
      // window on the screen.
      window.X = Screen.ActualWidth / 2 - window.DesiredWidth / 2;
      window.Y = Screen.ActualHeight / 2 - window.DesiredHeight / 2;
    }
Beispiel #7
0
    public MainMenuWindow()
    {
      // The window fill the whole screen.
      HorizontalAlignment = HorizontalAlignment.Stretch;
      VerticalAlignment = VerticalAlignment.Stretch;

      // The window itself (borders, title, background) should be invisible. Therefore, we have
      // added the "InvisibleWindow" style in the Theme.Xml.
      Style = "InvisibleWindow";

      var playButton = new Button
      {
        Margin = new Vector4F(10),
        Width = 200,
        Height = 60,
        Content = new TextBlock { Text = "Play" },
      };
      playButton.Click += (s, e) => DialogResult = true;

      var optionsButton = new Button
      {
        Margin = new Vector4F(10),
        Width = 200,
        Height = 60,
        Content = new TextBlock { Text = "Options" },
      };
      optionsButton.Click += (s, e) => new OptionsWindow().Show(this);

      var exitButton = new Button
      {
        Margin = new Vector4F(10),
        Width = 200,
        Height = 60,
        Content = new TextBlock { Text = "Exit" },
      };
      exitButton.Click += (s, e) => DialogResult = false;

      var stackPanel = new StackPanel
      {
        HorizontalAlignment = HorizontalAlignment.Center,
        VerticalAlignment = VerticalAlignment.Center,
      };
      stackPanel.Children.Add(playButton);
      stackPanel.Children.Add(optionsButton);
      stackPanel.Children.Add(exitButton);

      Content = stackPanel;
    }
Beispiel #8
0
    protected override void OnLoad()
    {
      base.OnLoad();

      if (_panel == null)
      {
        // Create and initialize the internal stack panel.
        _panel = new StackPanel();

        foreach (var item in Items)
          _panel.Children.Add(item);

        // The panel is the (only) visual child of the TreeView control.
        VisualChildren.Add(_panel);
      }
    }
Beispiel #9
0
        private void AddWindowComponents()
        {
            var menuWindow = new Window
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
            };
            _screen.Children.Add(menuWindow);

            var stackPanel = new StackPanel
            {
                Orientation = Orientation.Vertical,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Vector4F(150, 0, 0, 0),
            };
            menuWindow.Content = stackPanel;

            var startButton = new Button
            {
                Name = "StartButton",
                Content = new TextBlock { Text = "Start" },
                FocusWhenMouseOver = true,
            };
            startButton.Click += OnStartButtonClicked;

            stackPanel.Children.Add(startButton);

            startButton.Focus();

            _game.ResetElapsedTime();
        }
Beispiel #10
0
    public EasingWindow(IServiceLocator services) 
      : base(services)
    {
      _inputService = services.GetInstance<IInputService>();
      _animationService = services.GetInstance<IAnimationService>();

      Title = "EasingWindow";

      StackPanel stackPanel = new StackPanel { Margin = new Vector4F(8) };
      Content = stackPanel;

      TextBlock textBlock = new TextBlock
      {
        Text = "Test different Easing Functions in this window.",
        Margin = new Vector4F(0, 0, 0, 8),
      };
      stackPanel.Children.Add(textBlock);

      StackPanel horizontalPanel = new StackPanel
      {
        Orientation = Orientation.Horizontal,
        Margin = new Vector4F(0, 0, 0, 8)
      };
      stackPanel.Children.Add(horizontalPanel);

      textBlock = new TextBlock
      {
        Text = "Easing Function:",
        Width = 80,
        Margin = new Vector4F(0, 0, 8, 0),
      };
      horizontalPanel.Children.Add(textBlock);

      _functionDropDown = new DropDownButton
      {
        Width = 100,

        // The DropDownButton automatically converts the items to string (using ToString) and 
        // displays this string. This is not helpful for this sort of items. We want to display
        // the type name of the items instead. The following is a callback which creates a
        // TextBlock for each item. It is called when the drop-down list is opened.
        CreateControlForItem = item => new TextBlock { Text = item.GetType().Name },
      };
      horizontalPanel.Children.Add(_functionDropDown);

      _functionDropDown.Items.Add(new BackEase());
      _functionDropDown.Items.Add(new BounceEase());
      _functionDropDown.Items.Add(new CircleEase());
      _functionDropDown.Items.Add(new CubicEase());
      _functionDropDown.Items.Add(new ElasticEase());
      _functionDropDown.Items.Add(new ExponentialEase());
      _functionDropDown.Items.Add(new LogarithmicEase());
      _functionDropDown.Items.Add(new HermiteEase());
      _functionDropDown.Items.Add(new PowerEase());
      _functionDropDown.Items.Add(new QuadraticEase());
      _functionDropDown.Items.Add(new QuinticEase());
      _functionDropDown.Items.Add(new SineEase());
      _functionDropDown.SelectedIndex = 0;

      horizontalPanel = new StackPanel
      {
        Orientation = Orientation.Horizontal,
        Margin = new Vector4F(0, 0, 0, 8)
      };
      stackPanel.Children.Add(horizontalPanel);

      textBlock = new TextBlock
      {
        Text = "Easing Mode:",
        Width = 80,
        Margin = new Vector4F(0, 0, 8, 0),
      };
      horizontalPanel.Children.Add(textBlock);

      _modeDropDown = new DropDownButton
      {
        Width = 100,
      };
      horizontalPanel.Children.Add(_modeDropDown);

      _modeDropDown.Items.Add(EasingMode.EaseIn);
      _modeDropDown.Items.Add(EasingMode.EaseOut);
      _modeDropDown.Items.Add(EasingMode.EaseInOut);
      _modeDropDown.SelectedIndex = 0;

      _slider = new Slider
      {
        Margin = new Vector4F(0, 16, 0, 0),
        SmallChange = 0.01f,
        LargeChange = 0.1f,
        Minimum = -0.5f,
        Maximum = 1.5f,
        Width = 250,
        HorizontalAlignment = HorizontalAlignment.Center,
      };
      stackPanel.Children.Add(_slider);

      // Display the current value of the slider.
      var valueLabel = new TextBlock
      {
        Text = _slider.Value.ToString("F2"),
        HorizontalAlignment = HorizontalAlignment.Center,
        Margin = new Vector4F(0, 0, 0, 8),
      };
      stackPanel.Children.Add(valueLabel);

      // Update the text every time the slider value changes.
      var valueProperty = _slider.Properties.Get<float>("Value");
      valueProperty.Changed += (s, e) => valueLabel.Text = e.NewValue.ToString("F2");

      Button button = new Button
      {
        Content = new TextBlock { Text = "Animate" },
        HorizontalAlignment = HorizontalAlignment.Center,
        Margin = new Vector4F(0, 0, 0, 8),
      };
      button.Click += OnButtonClicked;
      stackPanel.Children.Add(button);

      textBlock = new TextBlock
      {
        Text = "(Press the Animate button to animate the slider\n"
                + "value using the selected EasingFunction.\n"
                + "The slider goes from -0.5 to 1.5. The animation\n"
                + "animates the value to 0 or to 1.)",
      };
      stackPanel.Children.Add(textBlock);

      // When the window is loaded, the window appears under the mouse cursor and flies to
      // its position.
      Vector2F mousePosition = _inputService.MousePosition;

      // The loading animation is a timeline group of three animations:
      // - One animations animates the RenderScale from (0, 0) to its current value.
      // - The other animations animate the X and Y positions from the mouse position 
      //   to current values.
      // The base class AnimatedWindow will apply this timeline group on this window 
      // when the window is loaded.
      TimelineGroup timelineGroup = new TimelineGroup
      {
        new Vector2FFromToByAnimation
        {
          TargetProperty = "RenderScale",
          From = new Vector2F(0, 0),
          Duration = TimeSpan.FromSeconds(0.3),
          EasingFunction = new HermiteEase { Mode = EasingMode.EaseOut },
        },
        new SingleFromToByAnimation
        {
          TargetProperty = "X",     
          From = mousePosition.X, 
          Duration = TimeSpan.FromSeconds(0.3),
        },        
        new SingleFromToByAnimation
        {
          TargetProperty = "Y",     
          From = mousePosition.Y, 
          Duration = TimeSpan.FromSeconds(0.3),
          EasingFunction = new QuadraticEase { Mode = EasingMode.EaseIn },
        },
      };
      // The default FillBehavior is "Hold". But this animation can be removed when it is finished. 
      // It should not "Hold" the animation value. If FillBehavior is set to Hold, we cannot
      // drag the window with the mouse because the animation overrides the value.
      timelineGroup.FillBehavior = FillBehavior.Stop;
      LoadingAnimation = timelineGroup;

      // The closing animation is a timeline group of three animations:
      // - One animations animates the RenderScale to (0, 0).
      // - The other animations animate the X and Y positions to the mouse position.
      // The base class AnimatedWindow will apply this timeline group on this window 
      // when the window is loaded.
      ClosingAnimation = new TimelineGroup
      {
        new Vector2FFromToByAnimation
        {
          TargetProperty = "RenderScale",
          To = new Vector2F(0, 0),
          Duration = TimeSpan.FromSeconds(0.3),
          EasingFunction = new HermiteEase { Mode = EasingMode.EaseIn },
        },
        new SingleFromToByAnimation
        {
          TargetProperty = "X",
          To = mousePosition.X,
          Duration = TimeSpan.FromSeconds(0.3),
        },        
        new SingleFromToByAnimation
        {
          TargetProperty = "Y",
          To = mousePosition.Y,
          Duration = TimeSpan.FromSeconds(0.3),
          EasingFunction = new QuadraticEase { Mode = EasingMode.EaseOut },
        },
      };
    }
Beispiel #11
0
    // Create a window which shows all controls.
    public WpWindow()
    {
      CanDrag = false;
      CanResize = false;
      HorizontalAlignment = HorizontalAlignment.Stretch;
      VerticalAlignment = VerticalAlignment.Stretch;

      Title = "DigitalRune Game UI Sample";

      // We handle the Closed event.
      Closed += OnClosed;

      var applicationTitle = new TextBlock
      {
        Text = "DIGITALRUNE GUI SAMPLE",
        Margin = new Vector4F(12, 0, 0, 0),
      };

      var pageTitle = new TextBlock
      {
        Text = "controls",
        Style = "TextBlockTitle",
        Margin = new Vector4F(9, -7, 0, 0),
      };

      var titlePanel = new StackPanel
      {
        Margin = new Vector4F(12, 24, 8, 8),
      };
      titlePanel.Children.Add(applicationTitle);
      titlePanel.Children.Add(pageTitle);

      var textBlock = new TextBlock
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        WrapText = true,
        Text = "This is a window with a lot of controls.\n" +
               "All controls are within a scroll viewer.\n" +
               "Tap-and-hold in window area to display the context menu of the window.",
        Style = "TextBlockSubtle"
      };

      var buttonEnabled = new Button
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "Button" },
      };

      var buttonDisabled = new Button
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "Button (Disabled)" },
        IsEnabled = false,
      };

      var checkBoxEnabled = new CheckBox
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "CheckBox" },
      };

      var checkBoxEnabledChecked = new CheckBox
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "CheckBox" },
        IsChecked = true,
      };

      var checkBoxDisabled = new CheckBox
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "CheckBox (Disabled)" },
        IsEnabled = false,
      };

      var checkBoxDisabledChecked = new CheckBox
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "CheckBox (Disabled)" },
        IsEnabled = false,
        IsChecked = true,
      };

      var checkBoxLotsOfText = new CheckBox
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "CheckBox with a lot of text that does not fit into a single line." },
      };

      var radioButton0 = new RadioButton
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "RadioButton" },
      };

      var radioButton1 = new RadioButton
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "RadioButton with a lot of text that does not fit into a single line." },
        IsChecked = true
      };

      var radioButton2 = new RadioButton
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "RadioButton" },
        IsEnabled = false,
      };

      var radioButton3 = new RadioButton
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "RadioButton (Disabled)" },
        IsEnabled = false,
        IsChecked = true,
        GroupName = "OtherGroup",   // Put in another group, so that the IsChecked state is not removed when the user clicks another radio button.
      };

      var dropDownButton = new DropDownButton
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        Title = "DROPDOWN ITEMS",
        SelectedIndex = 0,
      };
      // Add drop down items - each items is a string. Per default, the DropDownButton 
      // calls ToString() for each item and displays it in a text block.
      for (int i = 0; i < 30; i++)
        dropDownButton.Items.Add("DropDownItem " + i);

      var dropDownButtonDisabled = new DropDownButton
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        Title = "DROPDOWN ITEMS",
        IsEnabled = false,
        SelectedIndex = 0,
      };
      // Add drop down items - each items is a string. Per default, the DropDownButton 
      // calls ToString() for each item and displays it in a text block.
      for (int i = 0; i < 30; i++)
        dropDownButtonDisabled.Items.Add("DropDownItem " + i + "(Disabled)");

      var textBoxEnabled = new TextBox
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        GuideTitle = "GUIDE TITLE",
        GuideDescription = "Guide description:",
        Text = "TextBox (Enabled)"
      };

      var textBoxDisabled = new TextBox
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        Text = "TextBox (Disabled)",
        IsEnabled = false,
      };

      var slider = new Slider
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 24, 0, 24),
        Value = 33
      };

      var progressBar = new ProgressBar
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        Value = 66,
      };

      var progressBarIndeterminate = new ProgressBar
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        IsIndeterminate = true,
      };

      var stackPanel = new StackPanel
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
        Margin = new Vector4F(0, 0, 8, 0),
      };
      stackPanel.Children.Add(textBlock);
      stackPanel.Children.Add(buttonEnabled);
      stackPanel.Children.Add(buttonDisabled);
      stackPanel.Children.Add(checkBoxEnabled);
      stackPanel.Children.Add(checkBoxEnabledChecked);
      stackPanel.Children.Add(checkBoxDisabled);
      stackPanel.Children.Add(checkBoxDisabledChecked);
      stackPanel.Children.Add(checkBoxLotsOfText);
      stackPanel.Children.Add(radioButton0);
      stackPanel.Children.Add(radioButton1);
      stackPanel.Children.Add(radioButton2);
      stackPanel.Children.Add(radioButton3);
      stackPanel.Children.Add(dropDownButton);
      stackPanel.Children.Add(dropDownButtonDisabled);
      stackPanel.Children.Add(textBoxEnabled);
      stackPanel.Children.Add(textBoxDisabled);
      stackPanel.Children.Add(slider);
      stackPanel.Children.Add(progressBar);
      stackPanel.Children.Add(progressBarIndeterminate);

      var scrollViewer = new ScrollViewer
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
        Content = stackPanel,
        HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
        Margin = new Vector4F(24, 0, 8, 0)
      };

      var layoutRoot = new StackPanel
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
        Margin = new Vector4F(0, 0, 0, 0),
      };
      layoutRoot.Children.Add(titlePanel);
      layoutRoot.Children.Add(scrollViewer);

      Content = layoutRoot;

      // Add a context menu
      MenuItem item0 = new MenuItem { Content = new TextBlock { Text = "Item 0" }, };
      MenuItem item1 = new MenuItem { Content = new TextBlock { Text = "Item 1" }, };
      MenuItem item2 = new MenuItem { Content = new TextBlock { Text = "Item 2" }, };
      MenuItem item3 = new MenuItem { Content = new TextBlock { Text = "Item 3" }, };
      MenuItem item4 = new MenuItem { Content = new TextBlock { Text = "Item 4" }, };

      ContextMenu = new ContextMenu();
      ContextMenu.Items.Add(item0);
      ContextMenu.Items.Add(item1);
      ContextMenu.Items.Add(item2);
      ContextMenu.Items.Add(item3);
      ContextMenu.Items.Add(item4);
    }
Beispiel #12
0
    private void CreateGui()
    {
      // Remove old screen.
      if (_uiScreen != null)
        UIService.Screens.Remove(_uiScreen);

      // Load a UI theme, which defines the appearance and default values of UI controls.
      string themeName;
      if (_themeNumber == 0)
        themeName = "UI Themes/BlendBlue/Theme";
      else
        themeName = "UI Themes/Aero/Theme";

      Theme theme = ContentManager.Load<Theme>(themeName);

      // Create a UI renderer, which uses the theme info to renderer UI controls.
      UIRenderer renderer = new UIRenderer(Game, theme);

      // Create a UIScreen and add it to the UI service. The screen is the root of the 
      // tree of UI controls. Each screen can have its own renderer.
      _uiScreen = new UIScreen("SampleUIScreen", renderer);
      UIService.Screens.Add(_uiScreen);

      // Add a text block that displays the frame rate.
      _uiScreen.Children.Add(new FpsTextBlock
      {
        HorizontalAlignment = HorizontalAlignment.Right,
        VerticalAlignment = VerticalAlignment.Top,
        Margin = new Vector4F(40),
      });

      // Add a text label.
      var textBlock = new TextBlock
      {
        Text = "Press button to open window: ",
        Margin = new Vector4F(4)
      };

      // Add buttons that open samples.
      var button0 = new Button
      {
        Content = new TextBlock { Text = "Sample #1: Controls" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };
      button0.Click += (s, e) =>
      {
        var allControlsWindow = new AllControlsWindow(ContentManager, renderer);
        allControlsWindow.Show(_uiScreen);
      };

      var button1 = new Button
      {
        Content = new TextBlock { Text = "Sample #2: ScrollViewer" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button1.Click += (s, e) =>
      {
        var resizableWindow = new ResizableWindow(ContentManager);
        resizableWindow.Show(_uiScreen);
      };

      var button2 = new Button
      {
        Content = new TextBlock { Text = "Sample #3: Transformations" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button2.Click += (s, e) =>
      {
        var renderTransformWindow = new RenderTransformWindow();
        renderTransformWindow.Show(_uiScreen);
      };

      var button3 = new Button
      {
        Content = new TextBlock { Text = "Sample #4: Dialogs" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button3.Click += (s, e) =>
      {
        var dialogDemoWindow = new DialogDemoWindow();
        dialogDemoWindow.Show(_uiScreen);
      };

      var button4 = new Button
      {
        Content = new TextBlock { Text = "Sample #5: Console" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button4.Click += (s, e) =>
      {
        var consoleWindow = new ConsoleWindow();
        consoleWindow.Show(_uiScreen);
      };

      var button5 = new Button
      {
        Content = new TextBlock { Text = "Switch UI Theme" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button5.Click += (s, e) =>
      {
        // Set a flag. In the next Update() we will load a new theme.
        // Note: We should not load the theme here because the UI is currently updated.
        _changeTheme = true;
      };

      var stackPanel = new StackPanel { Margin = new Vector4F(40) };
      stackPanel.Children.Add(textBlock);
      stackPanel.Children.Add(button0);
      stackPanel.Children.Add(button1);
      stackPanel.Children.Add(button2);
      stackPanel.Children.Add(button3);
      stackPanel.Children.Add(button4);
      stackPanel.Children.Add(button5);
      _uiScreen.Children.Add(stackPanel);

      // Optional: If we want to allow the user to use buttons in the screen with 
      // keyboard or game pad, we have to make it a focus scope. Normally, only 
      // windows are focus scopes.
      _uiScreen.IsFocusScope = true;
      _uiScreen.Focus();
    }
Beispiel #13
0
    //--------------------------------------------------------------
    #region Methods
    //--------------------------------------------------------------

    /// <inheritdoc/>
    protected override void OnLoad()
    {
      base.OnLoad();

      // Create panel with items.
      if (_panel == null)
      {
        var contentStyle = ContentStyle;
        if (!string.IsNullOrEmpty(contentStyle))
        {
          _panel = new StackPanel
          {
            Style = contentStyle
          };

          foreach (var item in Items)
            _panel.Children.Add(item);

          Content = _panel;
        }
      }
    }
Beispiel #14
0
    //--------------------------------------------------------------
    #region Methods
    //--------------------------------------------------------------

    /// <inheritdoc/>
    protected override void OnLoad()
    {
      base.OnLoad();

      // _panel and _scrollViewer are only initialized once and reused. They are not destroyed
      // in Unload().
      if (_itemsPanel != null)
        return;

      string scrollViewerStyle = ContentStyle;
      if (string.IsNullOrEmpty(scrollViewerStyle))
        scrollViewerStyle = "ScrollViewer";

      _itemsPanel = new StackPanel
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Orientation = Orientation.Vertical,
      };

      _scrollViewer = new ScrollViewer
      {
        Style = scrollViewerStyle,
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
        HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
        VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
        Content = _itemsPanel,
      };

      if (GlobalSettings.PlatformID == PlatformID.WindowsPhone7 
          || GlobalSettings.PlatformID == PlatformID.WindowsPhone8)
      {
        // On Windows Phone the DropDown fills the whole screen and a title is displayed on top.
        var titleTextBlockStyle = TitleTextBlockStyle;
        if (!string.IsNullOrEmpty(titleTextBlockStyle))
        {
          var title = new TextBlock
          {
            Style = titleTextBlockStyle,
            Text = Owner.Title,
          };

          // Connect DropDownButton.Title with title.Text.
          var titleProperty = Owner.Properties.Get<string>(DropDownButton.TitlePropertyId);
          var textProperty = title.Properties.Get<string>(TextBlock.TextPropertyId);
          titleProperty.Changed += textProperty.Change;

          var outerPanel = new StackPanel
          {
            HorizontalAlignment = HorizontalAlignment.Stretch,
            VerticalAlignment = VerticalAlignment.Stretch,
            Orientation = Orientation.Vertical,
          };
          outerPanel.Children.Add(title);
          outerPanel.Children.Add(_scrollViewer);
          Content = outerPanel;

          // The ContentStyle should be applied to the scroll viewer - not the outer panel:
          outerPanel.Style = "StackPanel";
          _scrollViewer.Style = ContentStyle;
        }
        else
        {
          Content = _scrollViewer;
        }
      }
      else
      {
        Content = _scrollViewer;
      }
    }
        /// <summary>
        /// Load content for this game component
        /// </summary>
        protected override void LoadContent()
        {
            // TODO: Add your initialization code here
            var content = new ContentManager(Game.Services, "NeoforceTheme");
            Theme theme;
            theme = content.Load<Theme>("ThemeRed");

            // Create a UI renderer, which uses the theme info to renderer UI controls.
            var renderer = new UIRenderer(Game, theme);

            // Create a UIScreen and add it to the UI service. The screen is the root of
            // the tree of UI controls. Each screen can have its own renderer.
            _screen = new UIScreen("Default", renderer)
            {
                // Make the screen transparent.
                Background = new Color(0, 0, 0, 0),

            };
            var test = new Canvas()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
            };

            var maprender = new UIControls.GalaxyMapControl(Game.Services)
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
            };
            var minimap = new UIControls.MinimapControl(Game.Services);
            var miniMapWindow = new MiniMapWindow()
            {
                Height = 200,
                Width = 200,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Bottom,
                Name = "MiniMap"
            };
            var controlButtonPanel = new StackPanel()
            {
                Orientation = Orientation.Horizontal,
                VerticalAlignment = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Left
            };
            var testButton = new Button()
            {
                Height = 40,
                Width = 200
            };
            controlButtonPanel.Children.Add(testButton);
            miniMapWindow.Content = minimap;
            test.Children.Add(maprender);
            test.Children.Add(controlButtonPanel);
            test.Children.Add(miniMapWindow);

            var mainTabPanel = new TabControl
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch
            };

            var systemMap = new UIControls.SystemMapControl(Game.Services)
            {
                Opacity = 5,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                ViewData = new SystemMapViewModel() { Rings = new[]
                                                                  {
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 1", Scale = 1},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 1 - Moon", Scale = 0.4f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 2", Scale = 0.5f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 3", Scale = 0.7f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 3 - Moon 1", Scale = 0.3f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 3 - Moon 2", Scale = 0.3f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 4", Scale = 0.2f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 5", Scale = 0.9f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 6", Scale = 0.6f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 7", Scale = 0.3f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 8", Scale = 0.5f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 9", Scale = 0.8f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 9 - Moon 1", Scale = 0.2f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 9 - Moon 2", Scale = 0.2f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 9 - Moon 3", Scale = 0.2f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 9 - Moon 4", Scale = 0.3f},
                                                                                                                   }}
                                                                  }}
            };

            var planetMap = new PlanetMapControl(Game.Services)
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                ViewData = new PlanetMapViewModel()
                               {
                                   Name = "Earth",
                                   BuildingCells = new[,]
                                                       {
                                                           { new BuildingCellViewModel(), new BuildingCellViewModel { Type = CellMultiplier.ExtraEnergy }, new BuildingCellViewModel() },
                                                           { new BuildingCellViewModel(), new BuildingCellViewModel(), new BuildingCellViewModel { Type = CellMultiplier.ExtraEnergy } },
                                                           { new BuildingCellViewModel { Type = CellMultiplier.ExtraEnergy }, new BuildingCellViewModel(), new BuildingCellViewModel() }
                                                       }
                               }
            };

            mainTabPanel.Items.Add(new TabItem() { Content = new TextBlock() { Text = "Star map" }, TabPage = test });
            mainTabPanel.Items.Add(new TabItem() { Content = new TextBlock() { Text = "System map" }, TabPage = systemMap });
            mainTabPanel.Items.Add(new TabItem() { Content = new TextBlock() { Text = "Planet map" }, TabPage = planetMap });

            _console = new ConsoleWindow(_consoleManager);

            StartMenuScreen start = new StartMenuScreen(Game.Services);
            start.Init();
            _screen.Children.Add(start);

            //_screen.Children.Add(mainTabPanel);
            //_screen.Children.Add(_console);
            //_screen.Children.Add(miniMapWindow);
            //_screen.Children.Add(maprender);

            // Add the screen to the UI service.
            _uiService.Screens.Add(_screen);

            base.LoadContent();
        }
Beispiel #16
0
    private void AddButton(StackPanel panel, string text, Action clickHandler)
    {
      var button = new Button
      {
        Content = new TextBlock { Text = text },
        HorizontalAlignment = HorizontalAlignment.Stretch,
        MinWidth = 100
      };

      if (panel.Children.Count > 0)
        button.Margin = (panel.Orientation == Orientation.Horizontal) ? new Vector4F(3, 0, 0, 0) : new Vector4F(0, 3, 0, 0);

#if WINDOWS_PHONE || ANDROID || IOS
      button.Padding = new Vector4F(15);
#endif

      if (clickHandler != null)
        button.Click += (s, e) => clickHandler();

      panel.Children.Add(button);
    }
Beispiel #17
0
    public AllControlsWindow(ContentManager content, IUIRenderer renderer)
    {
      Title = "All Controls (This window has a context menu!)";
      CanResize = false;

      // The window content is set to a horizontal stack panel that contains two vertical
      // stack panels. The controls are added to the vertical panels.

      // ----- Button with text content
      var button0 = new Button
      {
        Content = new TextBlock { Text = "Button" },
        Margin = new Vector4F(4),
      };

      // ----- Button with mixed content
      // The content of a button is usually a text block but can be any UI control.
      // Let's try a button with image + text.
      var buttonContentPanel = new StackPanel { Orientation = Orientation.Horizontal };
      buttonContentPanel.Children.Add(new Image
      {
        Width = 16,
        Height = 16,
        Texture = content.Load<Texture2D>("Icon")
      });

      buttonContentPanel.Children.Add(new TextBlock
      {
        Margin = new Vector4F(4, 0, 0, 0),
        Text = "Button with image",
        VerticalAlignment = VerticalAlignment.Center,
      });

      var button1 = new Button
      {
        Content = buttonContentPanel,
        Margin = new Vector4F(4),
      };

      // ----- Drop-down button
      var dropDown = new DropDownButton
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(4),
        MaxDropDownHeight = 250,
      };
      for (int i = 0; i < 20; i++)
      {
        dropDown.Items.Add("DropDownItem " + i);
      }
      dropDown.SelectedIndex = 0;

      // ----- Check box
      var checkBox = new CheckBox
      {
        Margin = new Vector4F(4),
        Content = new TextBlock { Text = "CheckBox" },
      };

      // ----- Group of radio buttons
      var radioButton0 = new RadioButton
      {
        Margin = new Vector4F(4, 8, 4, 4),
        Content = new TextBlock { Text = "RadioButton0" },
      };

      var radioButton1 = new RadioButton
      {
        Margin = new Vector4F(4, 2, 4, 2),
        Content = new TextBlock { Text = "RadioButton1" },
      };

      var radioButton2 = new RadioButton
      {
        Margin = new Vector4F(4, 2, 4, 4),
        Content = new TextBlock { Text = "RadioButton1" },
      };

      // ----- Progress bar with value
      var progressBar0 = new ProgressBar
      {
        IsIndeterminate = false,
        Value = 75,
        Margin = new Vector4F(4, 8, 4, 4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Cursor = renderer.GetCursor("Wait"),
      };

      // ----- Progress bar without value (indeterminate)
      var progressBar1 = new ProgressBar
      {
        IsIndeterminate = true,
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Cursor = renderer.GetCursor("Wait"),
      };

      // ----- Slider connected with a text box.
      var slider = new Slider
      {
        Value = 60,
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };

      var sliderValue = new TextBlock
      {
        Margin = new Vector4F(4, 0, 4, 4),
        Text = "(Value = 60)",
        HorizontalAlignment = HorizontalAlignment.Right
      };

      // To connect the slider with the text box, we need to get the "Value" property.
      var valueProperty = slider.Properties.Get<float>("Value");
      // This property is a GameObjectProperty<float>. We can attach an event handler to 
      // the Changed event of the property.
      valueProperty.Changed += (s, e) => sliderValue.Text = "(Value = " + (int)e.NewValue + ")";

      // ----- Scroll bar
      var scrollBar = new ScrollBar
      {
        Style = "ScrollBarHorizontal",
        SmallChange = 1,
        LargeChange = 10,
        Value = 45,
        ViewportSize = 0.3f,
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };

      // Add the controls to the first vertical stack panel.
      var stackPanel0 = new StackPanel
      {
        Margin = new Vector4F(4),
      };
      stackPanel0.Children.Add(button0);
      stackPanel0.Children.Add(button1);
      stackPanel0.Children.Add(dropDown);
      stackPanel0.Children.Add(checkBox);
      stackPanel0.Children.Add(radioButton0);
      stackPanel0.Children.Add(radioButton1);
      stackPanel0.Children.Add(radioButton2);
      stackPanel0.Children.Add(progressBar0);
      stackPanel0.Children.Add(progressBar1);
      stackPanel0.Children.Add(slider);
      stackPanel0.Children.Add(sliderValue);
      stackPanel0.Children.Add(scrollBar);

      // ----- Group box
      var groupBox = new GroupBox
      {
        Title = "GroupBox",
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(4),
        Content = new TextBlock
        {
          Margin = new Vector4F(4),
          Text = "GroupBox Content"
        }
      };

      // ----- Tab control with 3 tab items
      var tabItem0 = new TabItem
      {
        TabPage = new TextBlock { Margin = new Vector4F(4), Text = "Page 0" },
        Content = new TextBlock { Text = "Item 0" },
      };
      var tabItem1 = new TabItem
      {
        TabPage = new TextBlock { Margin = new Vector4F(4), Text = "Page 1" },
        Content = new TextBlock { Text = "Item 1" },
      };
      var tabItem2 = new TabItem
      {
        TabPage = new TextBlock { Margin = new Vector4F(4), Text = "Page 2" },
        Content = new TextBlock { Text = "Item 2" },
      };
      var tabControl = new TabControl
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(4),
      };
      tabControl.Items.Add(tabItem0);
      tabControl.Items.Add(tabItem1);
      tabControl.Items.Add(tabItem2);

      // ----- Scroll viewer showing an image
      var image = new Image
      {
        Texture = content.Load<Texture2D>("Sky"),
      };

      var scrollViewer = new ScrollViewer
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        MinHeight = 100,
        HorizontalOffset = 200,
        VerticalOffset = 200,
        Height = 200,
      };
      scrollViewer.Content = image;

      // ----- Text box
      var textBox0 = new TextBox
      {
        Margin = new Vector4F(4),
        Text = "The quick brown fox jumps over the lazy dog.",
        MaxLines = 1,
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };

      // ----- Password box
      var textBox1 = new TextBox
      {
        Margin = new Vector4F(4),
        Text = "Secret password!",
        MaxLines = 1,
        IsPassword = true,
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };

      // ----- Multi-line text box
      var textBox2 = new TextBox
      {
        Margin = new Vector4F(4),
        Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifend, nulla semper vestibulum congue, lectus lectus aliquam magna, lobortis luctus sem magna sit amet elit. Integer at neque nec mi dapibus tincidunt. Maecenas elit quam, varius luctus rutrum ut, congue quis libero. In hac habitasse platea dictumst. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Phasellus eu ante eros. Etiam odio lectus, sagittis non dictum eu, faucibus vitae magna. Maecenas mi lorem, semper vel condimentum sit amet, vehicula quis nulla. Cras suscipit scelerisque orci, ac ullamcorper lorem egestas sed. Nulla facilisi. Nam justo enim, mollis nec condimentum non, consectetur vel purus. Curabitur ac diam vitae justo ultricies auctor.\n"
             + "Pellentesque interdum vehicula nisi sed congue. Etiam eget magna nec metus suscipit tincidunt et in lectus. Praesent sapien tortor, congue et semper eu, mattis ac lorem. Duis id est et justo tempus consectetur. Aliquam rutrum ullamcorper augue non varius. Fusce ornare lectus et ipsum lobortis ut venenatis tellus sodales. Proin venenatis scelerisque dui eu viverra. Pellentesque vitae risus eget tellus vehicula molestie et quis ante. Nulla imperdiet rhoncus ante, eu tristique ante euismod id. Sed varius varius hendrerit. Praesent massa tortor, gravida suscipit lacinia non, suscipit a ipsum. Integer vulputate, felis vitae consectetur bibendum, ante velit tincidunt nunc, in convallis erat dolor eu purus.",
        MinLines = 5,
        MaxLines = 5,
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };

      // ----- Console (command prompt)
      var console = new Console
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        MinHeight = 100,
      };

      // Add the controls to the second vertical stack panel.
      var stackPanel1 = new StackPanel
      {
        Width = 250,
        Margin = new Vector4F(4),
      };
      stackPanel1.Children.Add(groupBox);
      stackPanel1.Children.Add(tabControl);
      stackPanel1.Children.Add(scrollViewer);
      stackPanel1.Children.Add(textBox0);
      stackPanel1.Children.Add(textBox1);
      stackPanel1.Children.Add(textBox2);
      stackPanel1.Children.Add(console);

      // Add the two vertical stack panel into a horizontal stack panel.
      var stackPanelHorizontal = new StackPanel
      {
        Orientation = Orientation.Horizontal
      };
      stackPanelHorizontal.Children.Add(stackPanel0);
      stackPanelHorizontal.Children.Add(stackPanel1);

      Content = stackPanelHorizontal;

      // ----- Add a context menu to the window. (Each UI control can have its own context menu.)
      ContextMenu = new ContextMenu();

      // Add menu items.
      for (int i = 0; i < 10; i++)
      {
        var menuItem = new MenuItem
        {
          Content = new TextBlock { Text = "MenuItem" + i },
        };
        ContextMenu.Items.Add(menuItem);
      }
    }
Beispiel #18
0
    public UIAnimationSample(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.
      _graphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, _graphicsScreen);

      // Load a UI theme, which defines the appearance and default values of UI controls.
      Theme theme = ContentManager.Load<Theme>("UI Themes/BlendBlue/Theme");

      // Create a UI renderer, which uses the theme info to renderer UI controls.
      UIRenderer renderer = new UIRenderer(Game, theme);

      // Create a UIScreen and add it to the UI service. The screen is the root of the 
      // tree of UI controls. Each screen can have its own renderer.
      _uiScreen = new UIScreen("SampleUIScreen", renderer);
      UIService.Screens.Add(_uiScreen);

      // ----- Add buttons.
      Button button0 = new Button
      {
        Name = "Button0",
        Content = new TextBlock { Text = "Animate Buttons" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };
      button0.Click += (s, e) => PlayStartAnimation();

      Button button1 = new Button
      {
        Name = "Button1",
        Content = new TextBlock { Text = "Open FadingWindow" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button1.Click += (s, e) => new FadingWindow(Services).Show(_uiScreen);

      Button button2 = new Button
      {
        Name = "Button2",
        Content = new TextBlock { Text = "Open ScalingWindow" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button2.Click += (s, e) => new ScalingWindow(Services).Show(_uiScreen);

      Button button3 = new Button
      {
        Name = "Button3",
        Content = new TextBlock { Text = "Open RotatingWindow" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button3.Click += (s, e) => new RotatingWindow(Services).Show(_uiScreen);

      Button button4 = new Button
      {
        Name = "Button4",
        Content = new TextBlock { Text = "Open EasingWindow" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button4.Click += (s, e) => new EasingWindow(Services).Show(_uiScreen);

      Button button5 = new Button
      {
        Name = "Button5",
        Content = new TextBlock { Text = "Close All Windows" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button5.Click += (s, e) => CloseWindows();

      Button button6 = new Button
      {
        Name = "Button6",
        Content = new TextBlock { Text = "Exit" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button6.Click += (s, e) => Exit();

      _buttonStackPanel = new StackPanel { Margin = new Vector4F(40) };
      _buttonStackPanel.Children.Add(button0);
      _buttonStackPanel.Children.Add(button1);
      _buttonStackPanel.Children.Add(button2);
      _buttonStackPanel.Children.Add(button3);
      _buttonStackPanel.Children.Add(button4);
      _buttonStackPanel.Children.Add(button5);
      _buttonStackPanel.Children.Add(button6);
      _uiScreen.Children.Add(_buttonStackPanel);

      // Optional: If we want to allow the user to use buttons in the screen with 
      // keyboard or game pad, we have to make it a focus scope. Normally, only 
      // windows are focus scopes.
      _uiScreen.IsFocusScope = true;
      _uiScreen.Focus();

      PlayStartAnimation();
    }
Beispiel #19
0
    /// <summary>
    /// Called when "Menu" state is entered.
    /// </summary>
    private void OnEnterMenuScreen(object sender, StateEventArgs eventArgs)
    {
      // Show a main menu consisting of several buttons.

      // The user should be able to select individual buttons by using the 
      // D-pad on the gamepad or the arrow keys. Therefore we need to create
      // a Window. A Window manages the currently selected ("focused") control 
      // and automatically handles focus movement.
      // In this example the Window is invisible (no chrome) and stretches across 
      // the entire screen.
      _menuWindow = new Window
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
      };
      _uiScreen.Children.Add(_menuWindow);

      // The content of the Window is a vertical StackPanel containing several buttons.
      var stackPanel = new StackPanel
      {
        Orientation = Orientation.Vertical,
        HorizontalAlignment = HorizontalAlignment.Left,
        VerticalAlignment = VerticalAlignment.Bottom,
        Margin = new Vector4F(150, 0, 0, 200)
      };
      _menuWindow.Content = stackPanel;

      // The "Start" button starts the "Game" state.
      var startButton = new Button
      {
        Name = "StartButton",
        Content = new TextBlock { Text = "Start" },
        FocusWhenMouseOver = true,
      };
      startButton.Click += OnStartButtonClicked;

      // The buttons "Sub menu 1" and "Sub menu 2" show a dummy sub-menu.
      var subMenu1Button = new Button
      {
        Name = "SubMenu1Button",
        Content = new TextBlock { Text = "Sub-menu 1" },
        FocusWhenMouseOver = true,
      };
      subMenu1Button.Click += OnSubMenuButtonClicked;

      var subMenu2Button = new Button
      {
        Name = "SubMenu2Button",
        Content = new TextBlock { Text = "Sub-menu 2" },
        FocusWhenMouseOver = true,
      };
      subMenu2Button.Click += OnSubMenuButtonClicked;

      // The "Exit" button closes the application.
      var exitButton = new Button
      {
        Name = "ExitButton",
        Content = new TextBlock { Text = "Exit" },
        FocusWhenMouseOver = true,
      };
      exitButton.Click += OnExitButtonClicked;

      stackPanel.Children.Add(startButton);
      stackPanel.Children.Add(subMenu1Button);
      stackPanel.Children.Add(subMenu2Button);
      stackPanel.Children.Add(exitButton);

      // By default, the first button should be selected.
      startButton.Focus();

      // Slide the buttons in from the left (off screen) to make things more dynamic.
      AnimateFrom(stackPanel.Children, 0, new Vector2F(-300, 0));

      // The first time initialization of the GUI can take a short time. If we reset the elapsed 
      // time of the XNA game timer, the animation will start a lot smoother. 
      // (This works only if the XNA game uses a variable time step.)
      Game.ResetElapsedTime();
    }
Beispiel #20
0
    /// <summary>
    /// Called when "SubMenu" state is entered.
    /// </summary>
    private void OnEnterSubMenuScreen(object sender, StateEventArgs eventArgs)
    {
      // Similar to OnEnterMenuScreen.
      _subMenuWindow = new Window
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
      };
      _uiScreen.Children.Add(_subMenuWindow);

      var stackPanel = new StackPanel
      {
        Orientation = Orientation.Vertical,
        HorizontalAlignment = HorizontalAlignment.Left,
        VerticalAlignment = VerticalAlignment.Bottom,
        Margin = new Vector4F(150, 0, 0, 200)
      };
      _subMenuWindow.Content = stackPanel;

      var button1 = new Button
      {
        Name = "Item1Button",
        Content = new TextBlock { Text = "Item 1" },
        FocusWhenMouseOver = true,
      };
      var button2 = new Button
      {
        Name = "Item2Button",
        Content = new TextBlock { Text = "Item 2" },
        FocusWhenMouseOver = true,
      };
      var button3 = new Button
      {
        Name = "Item3Button",
        Content = new TextBlock { Text = "Item 3" },
        FocusWhenMouseOver = true,
      };
      var backButton = new Button
      {
        Name = "BackButton",
        Content = new TextBlock { Text = "Back" },
        FocusWhenMouseOver = true,
      };
      backButton.Click += OnBackButtonClicked;

      stackPanel.Children.Add(button1);
      stackPanel.Children.Add(button2);
      stackPanel.Children.Add(button3);
      stackPanel.Children.Add(backButton);

      button1.Focus();

      // Fade-in the buttons from the right.
      AnimateFrom(stackPanel.Children, 0, new Vector2F(300, 0));
    }
Beispiel #21
0
    private void InitializeGui()
    {
      // Add the GuiGraphicsScreen to the graphics service.
      _guiGraphicsScreen = new GuiGraphicsScreen(_services);
      _graphicsService.Screens.Add(_guiGraphicsScreen);

      // ----- Title (top left)
      _titleTextBlock = new TextBlock
      {
        Font = "DejaVuSans",
        Foreground = Color.White,
        Text = "No sample selected",
        X = 10,
        Y = 10,
      };
      _guiGraphicsScreen.UIScreen.Children.Add(_titleTextBlock);

      // ----- Info (bottom left)
      _infoPanel = new StackPanel
      {
        Margin = new Vector4F(10),
        HorizontalAlignment = HorizontalAlignment.Left,
        VerticalAlignment = VerticalAlignment.Bottom,
      };
      _guiGraphicsScreen.UIScreen.Children.Add(_infoPanel);
      _controllerTextBlock = new TextBlock
      {
        Font = "DejaVuSans",
        Foreground = Color.White,
        Text = "Controller disconnected. Press <Start> to use controller.",
      };
      _infoPanel.Children.Add(_controllerTextBlock);

#if XBOX
      _buttonsPanel = new StackPanel(); // Not used.
      var infoTextBlock = new TextBlock
      {
        Font = "DejaVuSans",
        Foreground = Color.White,
        Text = "Press <Left Stick> to show/hide help.",
      };
      _infoPanel.Children.Add(infoTextBlock);
      infoTextBlock = new TextBlock
      {
        Font = "DejaVuSans",
        Foreground = Color.White,
        Text = "Press <Back> to show/hide menu.",
      };
      _infoPanel.Children.Add(infoTextBlock);
#else
      // ----- Buttons (bottom right)
      _buttonsPanel = new StackPanel
      {
        Background = new Color(0, 0, 0, 64),
        Padding = new Vector4F(10),
        HorizontalAlignment = HorizontalAlignment.Right,
        VerticalAlignment = VerticalAlignment.Bottom,
      };
      _guiGraphicsScreen.UIScreen.Children.Add(_buttonsPanel);
      AddButton(_buttonsPanel, "Previous (PgUp)", LoadPreviousSample);
      AddButton(_buttonsPanel, "Next (PgDn)", LoadNextSample);
      AddButton(_buttonsPanel, "Menu (Esc)", ShowMenuWindow);
      AddButton(_buttonsPanel, "Help (F1)", ShowHelpWindow);
      AddButton(_buttonsPanel, "Profile (F3)", ShowProfilerWindow);
      AddButton(_buttonsPanel, "Options (F4)", ShowOptionsWindow);
#if !NETFX_CORE && !IOS
      AddButton(_buttonsPanel, "Exit (Alt-F4)", _game.Exit);
#endif
#endif

      // ----- FPS Counter (top right)
      _fpsPanel = new StackPanel
      {
        Margin = new Vector4F(10),
        HorizontalAlignment = HorizontalAlignment.Right,
        VerticalAlignment = VerticalAlignment.Top,
      };
      _guiGraphicsScreen.UIScreen.Children.Add(_fpsPanel);
      _updateFpsTextBlock = new TextBlock
      {
        Font = "DejaVuSans",
        Foreground = Color.Yellow,
        HorizontalAlignment = HorizontalAlignment.Right,
        Text = "Update",
      };
      _fpsPanel.Children.Add(_updateFpsTextBlock);
      _drawFpsTextBlock = new TextBlock
      {
        Font = "DejaVuSans",
        Foreground = Color.Yellow,
        HorizontalAlignment = HorizontalAlignment.Right,
        Text = "Draw",
      };
      _fpsPanel.Children.Add(_drawFpsTextBlock);

      // Create windows. (Hidden at start.)
      CreateMenuWindow();
      CreateProfilerWindow();
      CreateOptionsWindow();
      CreateHelpWindow();
    }
Beispiel #22
0
    //--------------------------------------------------------------
    #region Methods
    //--------------------------------------------------------------

    /// <inheritdoc/>
    protected override void OnLoad()
    {
      base.OnLoad();

      var tabItemPanelStyle = TabItemPanelStyle;
      if (!string.IsNullOrEmpty(tabItemPanelStyle))
      {
        _itemsPanel = new StackPanel
        {
          Style = tabItemPanelStyle,
        };

        foreach (var item in Items)
          _itemsPanel.Children.Add(item);

        VisualChildren.Add(_itemsPanel);
      }
    }
Beispiel #23
0
    private void CreateMenuWindow()
    {
      if (_menuWindow != null)
        return;

      // Window
      //   StackPanel (vertical)
      //     StackPanel (horizontal)
      //       Buttons
      //     TextBlock 
      //     TabControl
      //       TabItem                      * per category
      //         ScrollViewer
      //           StackPanel (vertical)
      //             StackPanel (vertical)  * per sample
      //               Button
      //               TextBlock

      _menuWindow = new Window
      {
        Name = "MenuWindow",
        Title = "Sample Browser",
        X = 50,
        Y = 50,
        IsVisible = false,
        HideOnClose = true
      };
      _menuWindow.Closed += OnWindowClosed;

      var panel = new StackPanel
      {
        Margin = new Vector4F(10),
        Orientation = Orientation.Vertical,
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch
      };
      _menuWindow.Content = panel;

      var buttonsPanel = new StackPanel
      {
        Orientation = Orientation.Horizontal
      };
      panel.Children.Add(buttonsPanel);

      AddButton(buttonsPanel, "Resume (Esc)", CloseWindows);
      AddButton(buttonsPanel, "Help (F1)", ShowHelpWindow);
      AddButton(buttonsPanel, "Profile (F3)", ShowProfilerWindow);
      AddButton(buttonsPanel, "Options (F4)", ShowOptionsWindow);
#if !NETFX_CORE && !IOS
      AddButton(buttonsPanel, "Exit (Alt-F4)", _game.Exit);
#endif

      var label = new TextBlock
      {
        Text = "Select Sample:",
        Margin = new Vector4F(2, 10, 0, 0)
      };
      panel.Children.Add(label);

      var tabControl = new TabControl
      {
        Margin = new Vector4F(0, 3, 0, 0),
        Width = 580,
#if WINDOWS_PHONE || ANDROID || IOS
        Height = 300
#else
        Height = 400
#endif
      };
      panel.Children.Add(tabControl);

      // Each tab shows a sample category (Base, Mathematics, Geometry, ...).
      var samplesByCategory = _samples.GroupBy(t => SampleAttribute.GetSampleAttribute(t).Category);
      int category = -1;
      foreach (var grouping in samplesByCategory)
      {
        category++;

        var tabItem = new TabItem
        {
          Content = new TextBlock { Text = grouping.Key.ToString() },
        };
        tabControl.Items.Add(tabItem);

        var scrollViewer = new ScrollViewer
        {
          HorizontalAlignment = HorizontalAlignment.Stretch,
          VerticalAlignment = VerticalAlignment.Stretch,
          HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled
        };
        tabItem.TabPage = scrollViewer;

        var itemsPanel = new StackPanel
        {
          Orientation = Orientation.Vertical,
          Margin = new Vector4F(5),
          HorizontalAlignment = HorizontalAlignment.Stretch,
          VerticalAlignment = VerticalAlignment.Stretch
        };
        scrollViewer.Content = itemsPanel;

        foreach (Type sample in grouping)
        {
          var item = new StackPanel
          {
            Orientation = Orientation.Vertical
          };
          itemsPanel.Children.Add(item);

          string title = sample.Name;
          var button = new Button
          {
            Content = new TextBlock { Text = title },
            Width = 200,
#if WINDOWS_PHONE || ANDROID || IOS
            Padding = new Vector4F(10),
#else
            Padding = new Vector4F(0, 5, 0, 5),
#endif
          };
          int sampleIndex = _samples.IndexOf(sample);
          button.Click += (s, e) =>
                          {
                            _nextSampleIndex = sampleIndex;
                            CloseWindows();
                          };
          item.Children.Add(button);

          string summary = SampleAttribute.GetSampleAttribute(sample).Summary;
          summary = summary.Replace("\r\n", " ");
          var summaryTextBlock = new TextBlock
          {
            Margin = new Vector4F(0, 3, 0, 12),
            Text = summary,
            WrapText = true
          };
          item.Children.Add(summaryTextBlock);
        }
      }
    }
Beispiel #24
0
    /// <inheritdoc/>
    protected override void OnUnload()
    {
      VisualChildren.Remove(_itemsPanel);
      _itemsPanel.Children.Clear();
      _itemsPanel = null;

      base.OnUnload();
    }
Beispiel #25
0
    public OptionsWindow()
    {
      Title = "Options (Switch tabs with LB and RB)";
      CanResize = false;
      CanDrag = false;
      HorizontalAlignment = HorizontalAlignment.Center;
      VerticalAlignment = VerticalAlignment.Center;

      var nameTextBlock = new TextBlock
      {
        Margin = new Vector4F(4),
        Text = "Your name:",
      };

      var nameTextBox = new TextBox
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Text = "Player1",
      };

      var passwordTextBlock = new TextBlock
      {
        Margin = new Vector4F(4),
        Text = "Your password:"******"Difficulty:",
      };

      var easyRadioButton = new RadioButton
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Content = new TextBlock { Text = "Easy" },
        GroupName = "Difficulty",
      };

      var normalRadioButton = new RadioButton
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Content = new TextBlock { Text = "Normal" },
        GroupName = "Difficulty",
        IsChecked = true,
      };

      var hardRadioButton = new RadioButton
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Content = new TextBlock { Text = "Hard" },
        GroupName = "Difficulty",
      };

      var modeTextBlock = new TextBlock
      {
        Margin = new Vector4F(4),
        Text = "Mode:",
      };

      var simulationRadioButton = new RadioButton
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Content = new TextBlock { Text = "Simulation" },
        GroupName = "Mode",
      };

      var arcadeRadioButton = new RadioButton
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Content = new TextBlock { Text = "Arcade" },
        GroupName = "Mode",
        IsChecked = true,
      };

      var generalPanel = new StackPanel
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };
      generalPanel.Children.Add(nameTextBlock);
      generalPanel.Children.Add(nameTextBox);
      generalPanel.Children.Add(passwordTextBlock);
      generalPanel.Children.Add(passwordTextBox);
      generalPanel.Children.Add(difficultyTextBlock);
      generalPanel.Children.Add(easyRadioButton);
      generalPanel.Children.Add(normalRadioButton);
      generalPanel.Children.Add(hardRadioButton);
      generalPanel.Children.Add(modeTextBlock);
      generalPanel.Children.Add(simulationRadioButton);
      generalPanel.Children.Add(arcadeRadioButton);

      var generalTab = new TabItem
      {
        TabPage = generalPanel,
        Content = new TextBlock { Text = "General" },
      };

      var resolutionTextBlock = new TextBlock
      {
        Margin = new Vector4F(4),
        Text = "Resolution:",
      };

      var resolutionDropDownButton = new DropDownButton
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        MaxDropDownHeight = 400,
      };
      resolutionDropDownButton.Items.Add("640 x 400");
      resolutionDropDownButton.Items.Add("800 x 480");
      resolutionDropDownButton.Items.Add("1024 x 768");
      resolutionDropDownButton.Items.Add("1280 x 720");
      resolutionDropDownButton.Items.Add("1920 x 1080");
      resolutionDropDownButton.Items.Add("1920 x 1200");
      resolutionDropDownButton.SelectedIndex = 3;

      var qualityTextBlock = new TextBlock
      {
        Margin = new Vector4F(4),
        Text = "Quality:",
      };

      var qualityValueTextBlock = new TextBlock
      {
        Margin = new Vector4F(4),
      };

      var qualityTextPanel = new StackPanel
      {
        Orientation = Orientation.Horizontal,
      };
      qualityTextPanel.Children.Add(qualityTextBlock);
      qualityTextPanel.Children.Add(qualityValueTextBlock);

      var qualitySlider = new Slider
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Minimum = 0,
        Maximum = 10,
        SmallChange = 1,        // This value is used when the user presses LEFT/RIGHT to move the slider.
        LargeChange = 1,        // This value is used when the user presses the slider (not the thumb).
      };

      // Each game object property (e.g. Slider.Minimum/Maximum/Margin/Value/...) has a Changing
      // and a Changed event. To use it, we have to get the property:
      GameProperty<float> sliderValueProperty = qualitySlider.Properties.Get<float>("Value");

      // We can use the Changing event to coerce the property value. For example: A normal slider
      // can have any values when dragged with the mouse. We can coerce the value to only allow
      // integer values!
      sliderValueProperty.Changing += (s, e) => e.CoercedValue = (float)Math.Round(e.CoercedValue);

      // We can use the Changed event to update dependent values. Here, we update the text block
      // text whenever the slider value changes.
      sliderValueProperty.Changed += (s, e) => qualityValueTextBlock.Text = qualitySlider.Value.ToString();

      // Initialize the slider value. This raises the Changing and Changed events, and the 
      // qualityValueTextBlock is updated too.
      qualitySlider.Value = 4;

      var graphicsPanel = new StackPanel
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };
      graphicsPanel.Children.Add(resolutionTextBlock);
      graphicsPanel.Children.Add(resolutionDropDownButton);
      graphicsPanel.Children.Add(qualityTextPanel);
      graphicsPanel.Children.Add(qualitySlider);

      var graphicsTab = new TabItem
      {
        TabPage = graphicsPanel,
        Content = new TextBlock { Text = "Graphics" },
      };

      var tabControl = new TabControl
      {
        Width = 300,
        Height = 300,
        Margin = new Vector4F(4)
      };
      tabControl.Items.Add(generalTab);
      tabControl.Items.Add(graphicsTab);

      var okButton = new Button
      {
        Width = 100,
        Margin = new Vector4F(4),
        Content = new TextBlock { Text = "OK (START)" },
        IsDefault = true,
      };
      okButton.Click += OnOK;

      var cancelButton = new Button
      {
        Width = 100,
        Margin = new Vector4F(4),
        Content = new TextBlock { Text = "Cancel (BACK)" },
        IsCancel = true,
      };
      cancelButton.Click += OnCancel;

      var buttonPanel = new StackPanel
      {
        Orientation = Orientation.Horizontal,
        HorizontalAlignment = HorizontalAlignment.Center,
      };
      buttonPanel.Children.Add(okButton);
      buttonPanel.Children.Add(cancelButton);

      var mainPanel = new StackPanel
      {
        Margin = new Vector4F(4)
      };
      mainPanel.Children.Add(tabControl);
      mainPanel.Children.Add(buttonPanel);

      Content = mainPanel;
    }
Beispiel #26
0
    protected override void OnLoad()
    {
      base.OnLoad();

      if (_panel == null)
      {
        // Create the internal stack panel.
        // The padding of this tree view item is used as the margin of the panel.
        _panel = new StackPanel
        {
          Margin = Padding,
        };

        // Whenever the padding is changed, the panel margin should be updated.
        var panelMargin = _panel.Properties.Get<Vector4F>(UIControl.MarginPropertyId);
        var padding = this.Properties.Get<Vector4F>(UIControl.PaddingPropertyId);
        padding.Changed += panelMargin.Change;

        // Add Items to the panel.
        _panel.Children.Add(Header);
        foreach (var item in Items)
          _panel.Children.Add(item);

        // The panel is the (only) visual child of the TreeView control.
        VisualChildren.Add(_panel);
      }
    }