Пример #1
0
        /// <summary>
        /// Creates the main window.
        /// </summary>
        /// <returns>The main window.</returns>
        public Window CreateWindow()
        {
            // Create a window object and set its size to the size of the 
            // display.
            mainWindow = new Window();
            mainWindow.Width = SystemMetrics.ScreenWidth;
            mainWindow.Height = SystemMetrics.ScreenHeight;

            // Detect landscape or portrait so the program can adjust its 
            // layout.
            bool portrait =
                SystemMetrics.ScreenWidth < SystemMetrics.ScreenHeight;

            // Create the main stack panel.
            StackPanel stack = new StackPanel(portrait ?
                Orientation.Vertical : Orientation.Horizontal);

            // Create stack panels for the current temperature and target 
            // temperature.
            StackPanel stack1 = new StackPanel(Orientation.Vertical);
            StackPanel stack2 = new StackPanel(Orientation.Vertical);

            // Create border panels for the current temperature and target 
            // temperature.
            BorderPanel panel1;
            BorderPanel panel2;

            // Detect portrait or landscape orientation.
            if (portrait)
            {

                // If in portrait mode, set the width to the screen width and 
                // height to 1/4 and 3/4.
                panel1 = new BorderPanel(SystemMetrics.ScreenWidth,
                    (int)(SystemMetrics.ScreenHeight * .25));
                panel2 = new BorderPanel(SystemMetrics.ScreenWidth,
                    (int)(SystemMetrics.ScreenHeight * .75));
            }
            else
            {
                // Otherwise, set the width and height to 1/2 and 1/2, 
                // respectively.
                panel1 = new BorderPanel(SystemMetrics.ScreenWidth / 2,
                    SystemMetrics.ScreenHeight);
                panel2 = new BorderPanel(SystemMetrics.ScreenWidth / 2,
                    SystemMetrics.ScreenHeight);
            }

            // Add the border panels to the panels containing the current 
            // temperature and target temperature.
            panel1.Children.Add(stack1);
            panel2.Children.Add(stack2);

            // Add the stack panels to the border panels.
            stack.Children.Add(panel1);
            stack.Children.Add(panel2);

            // Create text controls for the current temperature.
            _textCurrentTemp = new Text();
            _textCurrentTemp.Font =
                Resources.GetFont(Resources.FontResources.nina48);
            _textCurrentTemp.TextContent =
                Resources.GetString(Resources.StringResources.InitialTemp);
            _textCurrentTemp.HorizontalAlignment =
                Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
            _textCurrentTemp.VerticalAlignment =
                Microsoft.SPOT.Presentation.VerticalAlignment.Center;

            Text currentLabel = new Text();
            currentLabel.Font =
                Resources.GetFont(Resources.FontResources.nina14);
            currentLabel.TextContent =
                Resources.GetString(Resources.StringResources.CurrentTemp);
            currentLabel.HorizontalAlignment =
                Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
            currentLabel.VerticalAlignment =
                Microsoft.SPOT.Presentation.VerticalAlignment.Center;

            // Add the text controls to the current temperature stack panel.
            stack1.Children.Add(currentLabel);
            stack1.Children.Add(_textCurrentTemp);

            // Create controls for the target temperature.
            _textTargetTemp = new Text();
            _textTargetTemp.Font =
                Resources.GetFont(Resources.FontResources.nina48);
            _textTargetTemp.TextContent =
                Resources.GetString(Resources.StringResources.InitialTemp);
            _textTargetTemp.HorizontalAlignment =
                HorizontalAlignment.Center;
            _textTargetTemp.VerticalAlignment =
                VerticalAlignment.Center;

            Text targetLabel = new Text();
            targetLabel.Font =
                Resources.GetFont(Resources.FontResources.nina14);
            targetLabel.TextContent =
                Resources.GetString(Resources.StringResources.TargetTemp);
            targetLabel.HorizontalAlignment = HorizontalAlignment.Center;
            targetLabel.VerticalAlignment = VerticalAlignment.Center;

            // Create the air conditioner or heater status indicator.
            _statusIndicator = new StatusIndicator();

            // Add the controls to the target temperature stack panel.
            stack2.Children.Add(targetLabel);
            stack2.Children.Add(_textTargetTemp);
            stack2.Children.Add(_statusIndicator);

            // Add instructions to the target temperature stack panel.
            TextFlow instructions = new TextFlow();
            instructions.HorizontalAlignment = HorizontalAlignment.Center;
            instructions.VerticalAlignment = VerticalAlignment.Center;
            instructions.TextAlignment = TextAlignment.Center;
            instructions.TextRuns.Add(new TextRun("Up Button to Increase",
                Resources.GetFont(Resources.FontResources.nina14), Color.Black));
            instructions.TextRuns.Add(TextRun.EndOfLine);
            instructions.TextRuns.Add(new TextRun("Down Button to Decrease",
                Resources.GetFont(Resources.FontResources.nina14), Color.Black));
            instructions.TextRuns.Add(TextRun.EndOfLine);
            instructions.TextRuns.Add(new TextRun(
                "Select Button to Toggle Celsius / Fahrenheit",
                Resources.GetFont(Resources.FontResources.nina14), Color.Black));
            stack2.Children.Add(instructions);

            // Set the main window child to the main horizontal stack panel.
            mainWindow.Child = stack;

            // Connect the button handler to all of the buttons.
            mainWindow.AddHandler(Buttons.ButtonUpEvent,
                new RoutedEventHandler(OnButtonUp), false);

            // Set the window visibility to Visible.
            mainWindow.Visibility = Visibility.Visible;

            // Attach the button focus to the window.
            Buttons.Focus(mainWindow);

            // Create the timer that will check the current temperature.
            _timer = new DispatcherTimer(mainWindow.Dispatcher);
            _timer.Interval = new TimeSpan(0, 0, 0, 0, 50);
            _timer.Tick += new EventHandler(OnTimer);
            _timer.Start();

            return mainWindow;
        }
Пример #2
0
        /// <summary>
        /// Creates the main window.
        /// </summary>
        /// <returns>The main window.</returns>
        public Window CreateWindow()
        {
            // Create a window object and set its size to the size of the
            // display.
            mainWindow        = new Window();
            mainWindow.Width  = SystemMetrics.ScreenWidth;
            mainWindow.Height = SystemMetrics.ScreenHeight;

            // Detect landscape or portrait so the program can adjust its
            // layout.
            bool portrait =
                SystemMetrics.ScreenWidth < SystemMetrics.ScreenHeight;

            // Create the main stack panel.
            StackPanel stack = new StackPanel(portrait ?
                                              Orientation.Vertical : Orientation.Horizontal);

            // Create stack panels for the current temperature and target
            // temperature.
            StackPanel stack1 = new StackPanel(Orientation.Vertical);
            StackPanel stack2 = new StackPanel(Orientation.Vertical);

            // Create border panels for the current temperature and target
            // temperature.
            BorderPanel panel1;
            BorderPanel panel2;

            // Detect portrait or landscape orientation.
            if (portrait)
            {
                // If in portrait mode, set the width to the screen width and
                // height to 1/4 and 3/4.
                panel1 = new BorderPanel(SystemMetrics.ScreenWidth,
                                         (int)(SystemMetrics.ScreenHeight * .25));
                panel2 = new BorderPanel(SystemMetrics.ScreenWidth,
                                         (int)(SystemMetrics.ScreenHeight * .75));
            }
            else
            {
                // Otherwise, set the width and height to 1/2 and 1/2,
                // respectively.
                panel1 = new BorderPanel(SystemMetrics.ScreenWidth / 2,
                                         SystemMetrics.ScreenHeight);
                panel2 = new BorderPanel(SystemMetrics.ScreenWidth / 2,
                                         SystemMetrics.ScreenHeight);
            }

            // Add the border panels to the panels containing the current
            // temperature and target temperature.
            panel1.Children.Add(stack1);
            panel2.Children.Add(stack2);

            // Add the stack panels to the border panels.
            stack.Children.Add(panel1);
            stack.Children.Add(panel2);

            // Create text controls for the current temperature.
            _textCurrentTemp      = new Text();
            _textCurrentTemp.Font =
                Resources.GetFont(Resources.FontResources.nina48);
            _textCurrentTemp.TextContent =
                Resources.GetString(Resources.StringResources.InitialTemp);
            _textCurrentTemp.HorizontalAlignment =
                Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
            _textCurrentTemp.VerticalAlignment =
                Microsoft.SPOT.Presentation.VerticalAlignment.Center;

            Text currentLabel = new Text();

            currentLabel.Font =
                Resources.GetFont(Resources.FontResources.nina14);
            currentLabel.TextContent =
                Resources.GetString(Resources.StringResources.CurrentTemp);
            currentLabel.HorizontalAlignment =
                Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
            currentLabel.VerticalAlignment =
                Microsoft.SPOT.Presentation.VerticalAlignment.Center;

            // Add the text controls to the current temperature stack panel.
            stack1.Children.Add(currentLabel);
            stack1.Children.Add(_textCurrentTemp);

            // Create controls for the target temperature.
            _textTargetTemp      = new Text();
            _textTargetTemp.Font =
                Resources.GetFont(Resources.FontResources.nina48);
            _textTargetTemp.TextContent =
                Resources.GetString(Resources.StringResources.InitialTemp);
            _textTargetTemp.HorizontalAlignment =
                HorizontalAlignment.Center;
            _textTargetTemp.VerticalAlignment =
                VerticalAlignment.Center;

            Text targetLabel = new Text();

            targetLabel.Font =
                Resources.GetFont(Resources.FontResources.nina14);
            targetLabel.TextContent =
                Resources.GetString(Resources.StringResources.TargetTemp);
            targetLabel.HorizontalAlignment = HorizontalAlignment.Center;
            targetLabel.VerticalAlignment   = VerticalAlignment.Center;

            // Create the air conditioner or heater status indicator.
            _statusIndicator = new StatusIndicator();

            // Add the controls to the target temperature stack panel.
            stack2.Children.Add(targetLabel);
            stack2.Children.Add(_textTargetTemp);
            stack2.Children.Add(_statusIndicator);

            // Add instructions to the target temperature stack panel.
            TextFlow instructions = new TextFlow();

            instructions.HorizontalAlignment = HorizontalAlignment.Center;
            instructions.VerticalAlignment   = VerticalAlignment.Center;
            instructions.TextAlignment       = TextAlignment.Center;
            instructions.TextRuns.Add(new TextRun("Up Button to Increase",
                                                  Resources.GetFont(Resources.FontResources.nina14), Color.Black));
            instructions.TextRuns.Add(TextRun.EndOfLine);
            instructions.TextRuns.Add(new TextRun("Down Button to Decrease",
                                                  Resources.GetFont(Resources.FontResources.nina14), Color.Black));
            instructions.TextRuns.Add(TextRun.EndOfLine);
            instructions.TextRuns.Add(new TextRun(
                                          "Select Button to Toggle Celsius / Fahrenheit",
                                          Resources.GetFont(Resources.FontResources.nina14), Color.Black));
            stack2.Children.Add(instructions);

            // Set the main window child to the main horizontal stack panel.
            mainWindow.Child = stack;

            // Connect the button handler to all of the buttons.
            mainWindow.AddHandler(Buttons.ButtonUpEvent,
                                  new RoutedEventHandler(OnButtonUp), false);

            // Set the window visibility to Visible.
            mainWindow.Visibility = Visibility.Visible;

            // Attach the button focus to the window.
            Buttons.Focus(mainWindow);

            // Create the timer that will check the current temperature.
            _timer          = new DispatcherTimer(mainWindow.Dispatcher);
            _timer.Interval = new TimeSpan(0, 0, 0, 0, 50);
            _timer.Tick    += new EventHandler(OnTimer);
            _timer.Start();

            return(mainWindow);
        }