예제 #1
0
        private void CreateNewToDoItem(TextBox textBox)
        {
            var list = textBox.DataContext as ViewModels.TodoListViewModel;
            list.AddCommand.Execute(textBox.Text);
            textBox.Text = string.Empty;
            textBox.Focus(Windows.UI.Xaml.FocusState.Programmatic);

            if (AddNewItemConfirmButton != null)
                AddNewItemConfirmButton.IsEnabled = false;
        }
예제 #2
0
        public bool ShowKeyboardInput()
        {
            if (IsXAML)
            {
                // RunAsync all of the UI info.
                dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // Create a TextBox that will be added to our view but hidden
                    hiddenKeyInput         = new Windows.UI.Xaml.Controls.TextBox();
                    hiddenKeyInput.Opacity = 0;

                    // We will only be generating one character at a time and does not
                    // matter about the font.  All we need is the text.
                    hiddenKeyInput.Width    = 1;
                    hiddenKeyInput.Height   = 1;
                    hiddenKeyInput.MaxWidth = 1;

                    // Create an input scope for us.  Probably not needed
                    var scope = new Windows.UI.Xaml.Input.InputScope();
                    var name  = new Windows.UI.Xaml.Input.InputScopeName();

                    name.NameValue = Windows.UI.Xaml.Input.InputScopeNameValue.Default;
                    scope.Names.Add(name);

                    hiddenKeyInput.InputScope = scope;

                    // Set spell checking off.
                    hiddenKeyInput.IsSpellCheckEnabled = false;

                    // Add our hidden TextBox to our panel
                    content.Children.Add(hiddenKeyInput);


                    // InputPane does not work in this scenario
                    // We need to listen to GotFocus and LostFocus Events
                    hiddenKeyInput.GotFocus  += OnGotFocus;
                    hiddenKeyInput.LostFocus += OnLostFocuc;


                    // Hook up our key delegates
                    hiddenKeyInput.KeyDown += OnKeyDown;
                    hiddenKeyInput.KeyUp   += OnKeyUp;

                    // enable us and set focus
                    hiddenKeyInput.IsEnabled = true;
                    hiddenKeyInput.Focus(Windows.UI.Xaml.FocusState.Programmatic);
                }
                                    );
            }
            else
            {
            }
            return(true);
        }
예제 #3
0
        /// <summary>
        /// Visualizza una finestra di dialogo con TextBox
        /// </summary>
        public static async Task<DialogTextBoxResult> DialogTextBox(string content, string title, string box="", string ok="ok", string cancel="annulla", string sub=null, string header=null, InputScopeNameValue scopename=InputScopeNameValue.Default)
        {
            DialogTextBoxResult risposta = new DialogTextBoxResult();
            risposta.result=false;
            risposta.output=null;



            StackPanel stack = new StackPanel();

            if(content != null)
            {
                TextBlock contenuto = new TextBlock();
                contenuto.Text = content;
                stack.Children.Add(contenuto);
            }

            InputScope scope = new InputScope();
            scope.Names.Add(new InputScopeName(scopename));

            TextBox tb = new TextBox();
            tb.Text=box;
            tb.InputScope = scope;
            tb.Header = header;
            tb.Margin = new Thickness(0,5,0,5);
            stack.Children.Add(tb);

            if(sub!=null)
            {
                TextBlock subba = new TextBlock();
                subba.Text=sub;
                subba.TextWrapping = TextWrapping.Wrap;
                stack.Children.Add(subba);
            }


            ContentDialog cd = new ContentDialog();
            cd.Title = title;
            cd.Content = stack;


            cd.PrimaryButtonText = ok;
            cd.PrimaryButtonClick+= (s, ev) =>
            {
                risposta.result=true;
                risposta.output=tb.Text;
            };

            cd.SecondaryButtonText=cancel;
            cd.SecondaryButtonClick+= (s, ev) =>
            {
                risposta.result=false;
                risposta.output=null;
            };

            cd.Opened+=(s, ev) =>
            {
                tb.Focus(FocusState.Keyboard);
                tb.SelectAll();
            };

            await cd.ShowAsync();

            return risposta;
        }
        /// <summary>
        /// Display the keyboard input panel
        /// </summary>
        private static void BeginShowKeyboardInput_Win8(string title, string body, string initialValue)
        {
            TextBlock textTitle;
            TextBlock textBody;
            Grid gridInputArea;
            StackPanel stackButtons;

            // Create a grid to add to the page. The grid will fill the entire page and has a
            // semi-transparent black background to "mark" the graphics behind.
            _gridBackground = new Grid();
            _gridBackground.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch;
            _gridBackground.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch;
            _gridBackground.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
            _gridBackground.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            _gridBackground.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
            _gridBackground.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(100, 0, 0, 0));

            // Create another grid to appear as a strip across the center of the screen, inside which
            // the popup text, input box and buttons will be displayed
            gridInputArea = new Grid();
            gridInputArea.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 220, 220, 220));
            gridInputArea.HorizontalAlignment = HorizontalAlignment.Stretch;
            gridInputArea.VerticalAlignment = VerticalAlignment.Stretch;
            gridInputArea.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            gridInputArea.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            gridInputArea.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            gridInputArea.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            gridInputArea.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(20, GridUnitType.Star) });
            gridInputArea.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(60, GridUnitType.Star) });
            gridInputArea.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(20, GridUnitType.Star) });
            _gridBackground.Children.Add(gridInputArea);
            Grid.SetRow(gridInputArea, 1);

            // If we have some text, add it to the grid
            if (!string.IsNullOrEmpty(title))
            {
                textTitle = new TextBlock();
                textTitle.Text = title;
                textTitle.TextWrapping = TextWrapping.Wrap;
                textTitle.Foreground = new SolidColorBrush(Colors.Black);
                textTitle.FontSize = 25;
                textTitle.Margin = new Thickness(0, 20, 0, 0);
                gridInputArea.Children.Add(textTitle);
                Grid.SetRow(textTitle, 0);
                Grid.SetColumn(textTitle, 1);
            }

            // Add the body text
            textBody = new TextBlock();
            textBody.Text = body;
            textBody.TextWrapping = TextWrapping.Wrap;
            textBody.Foreground = new SolidColorBrush(Colors.Black);
            textBody.FontSize = 20;
            textBody.Margin = new Thickness(0, 20, 0, 20);
            gridInputArea.Children.Add(textBody);
            Grid.SetRow(textBody, 1);
            Grid.SetColumn(textBody, 1);

            // Create a textbox for the user to enter text into
            _textboxInput = new TextBox();
            _textboxInput.HorizontalAlignment = HorizontalAlignment.Stretch;
            _textboxInput.VerticalAlignment = VerticalAlignment.Stretch;
            _textboxInput.Height = 20;
            _textboxInput.Background = new SolidColorBrush(Colors.White);
            _textboxInput.Text = initialValue;
            _textboxInput.KeyDown += textboxInput_KeyDown;
            gridInputArea.Children.Add(_textboxInput);
            Grid.SetRow(_textboxInput, 2);
            Grid.SetColumn(_textboxInput, 1);

            // The final row of the popup is occupied by a StackPanel inside which the buttons are displayed
            stackButtons = new StackPanel();
            stackButtons.Orientation = Orientation.Horizontal;
            stackButtons.HorizontalAlignment = HorizontalAlignment.Right;
            stackButtons.Margin = new Thickness(0, 20, 0, 20);
            gridInputArea.Children.Add(stackButtons);
            Grid.SetRow(stackButtons, 3);
            Grid.SetColumn(stackButtons, 1);

            // Add the OK button...
            _buttonOK = new Button();
            _buttonOK.Content = "OK";
            _buttonOK.Padding = new Thickness(0, 5, 0, 5);
            _buttonOK.Width = 110;
            _buttonOK.Foreground = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 30, 30, 30));
            _buttonOK.Click += buttonOption_Click;
            stackButtons.Children.Add(_buttonOK);

            // ...and the Cancel button
            _buttonCancel = new Button();
            _buttonCancel.Content = "Cancel";
            _buttonCancel.Padding = new Thickness(0, 5, 0, 5);
            _buttonCancel.Width = 110;
            _buttonCancel.Foreground = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 30, 30, 30));
            _buttonCancel.Click += buttonOption_Click;
            stackButtons.Children.Add(_buttonCancel);

            // Add the whole grid to the game page
            _parent.Children.Add(_gridBackground);

            // Set focus into the input field
            _textboxInput.Focus(FocusState.Programmatic);
            _textboxInput.SelectionStart = _textboxInput.Text.Length;

            // Indicate that the input panel is now visible
            KeyboardInputIsVisible = true;
        }
예제 #5
0
        public bool ShowKeyboardInput()
        {

            if (IsXAML)
            {
                // RunAsync all of the UI info.
                dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {

                        // Create a TextBox that will be added to our view but hidden
                        hiddenKeyInput = new Windows.UI.Xaml.Controls.TextBox();
                        hiddenKeyInput.Opacity = 0;

                        // We will only be generating one character at a time and does not
                        // matter about the font.  All we need is the text.
                        hiddenKeyInput.Width = 1;
                        hiddenKeyInput.Height = 1;
                        hiddenKeyInput.MaxWidth = 1;

                        // Create an input scope for us.  Probably not needed
                        var scope = new Windows.UI.Xaml.Input.InputScope();
                        var name = new Windows.UI.Xaml.Input.InputScopeName();

                        name.NameValue = Windows.UI.Xaml.Input.InputScopeNameValue.Default;
                        scope.Names.Add(name);

                        hiddenKeyInput.InputScope = scope;

                        // Set spell checking off.
                        hiddenKeyInput.IsSpellCheckEnabled = false;

                        // Add our hidden TextBox to our panel
                        content.Children.Add(hiddenKeyInput);


                        // InputPane does not work in this scenario
                        // We need to listen to GotFocus and LostFocus Events
                        hiddenKeyInput.GotFocus += OnGotFocus;
                        hiddenKeyInput.LostFocus += OnLostFocuc;


                        // Hook up our key delegates
                        hiddenKeyInput.KeyDown += OnKeyDown;
                        hiddenKeyInput.KeyUp += OnKeyUp;

                        // enable us and set focus
                        hiddenKeyInput.IsEnabled = true;
                        hiddenKeyInput.Focus(Windows.UI.Xaml.FocusState.Programmatic);
                    }
                );
            }
            else
            {

            }
            return true;
        }
        /// <summary>
        /// Preforms the selected edit type on the text box given.
        /// </summary>
        /// <param name="textBox"></param>
        /// <param name="editType"></param>
        public static void DoEdit(TextBox textBox, VisualHelperTypes editType)
        {
            // First refocus the text box since the user clicked a button.
            // We need to do this quickly so the virt keyboard doesn't move. 
            textBox.Focus(FocusState.Programmatic);

            // Get some vars
            int selStart = textBox.SelectionStart;
            int selLength = textBox.SelectionLength;
            string curText = textBox.Text;
            string insertNewLine = null;
            string insertAtEnd = null;
            bool isLink = false;
            bool hasExampleText = false;

            // Depending on the type see what we can do.
            switch (editType)
            {
                case HelperControls.VisualHelperTypes.Bold:
                    if (selLength != 0)
                    {
                        // Wrap the selected text
                        textBox.Text = curText.Insert(selStart + selLength, "**").Insert(selStart, "**");
                    }
                    else
                    {
                        // Or add to the end
                        insertAtEnd = $"**{c_exampleText}**";
                        hasExampleText = true;
                    }
                    break;
                case HelperControls.VisualHelperTypes.Italic:
                    if (selLength != 0)
                    {
                        // Wrap the selected text
                        textBox.Text = curText.Insert(selStart + selLength, "*").Insert(selStart, "*");
                    }
                    else
                    {
                        // Or add to the end
                        insertAtEnd = $"*{c_exampleText}*";
                        hasExampleText = true;
                    }
                    break;
                case HelperControls.VisualHelperTypes.Link:
                    if (selLength != 0)
                    {
                        // Wrap the selected text
                        textBox.Text = curText.Insert(selStart + selLength, $"]({c_exampleUrl})").Insert(selStart, "[");
                    }
                    else
                    {
                        // Or add to the end
                        insertAtEnd = $"[{c_exampleText}]({c_exampleUrl})";
                    }
                    isLink = true;
                    break;
                case HelperControls.VisualHelperTypes.NewLine:
                    int injectPos = selStart;
                    // Inject the new line at the current pos
                    textBox.Text = curText.Insert(injectPos, "  \r\n");
                    // Move the selection to the end of insert
                    textBox.SelectionStart = injectPos + 3;
                    break;
                case HelperControls.VisualHelperTypes.Quote:
                    insertNewLine = "> ";
                    break;
                case HelperControls.VisualHelperTypes.List:
                    insertNewLine = "* ";
                    break;
                case HelperControls.VisualHelperTypes.NumberedList:
                    insertNewLine = "1. ";
                    break;
                case HelperControls.VisualHelperTypes.Code:
                    insertNewLine = "    ";
                    break;

            }

            // If the insert on new line is not null we need to find the last new line and
            // insert the text.
            if (insertNewLine != null)
            {
                // Search for a new line.
                int searchStart = selStart == curText.Length ? selStart - 1 : selStart;
                int indexLastNewLine = curText.LastIndexOf('\n', searchStart);

                // Insert the text
                textBox.Text = curText.Insert(indexLastNewLine + 1, insertNewLine);

                // Move the cur to the end.
                textBox.SelectionStart = indexLastNewLine + 1 + insertNewLine.Length;
            }

            // If this isn't null we have something to add at the end of the current text.
            if (insertAtEnd != null)
            {
                // If the last char isn't a space add one.
                if (textBox.Text.Length > 0 && !Char.IsWhiteSpace(textBox.Text[textBox.Text.Length - 1]))
                {
                    textBox.Text += ' ';
                }
                textBox.Text += insertAtEnd;
                textBox.SelectionStart = textBox.Text.Length;
            }

            // If we added a link try to select the example url
            if (isLink)
            {
                int urlStart = textBox.Text.IndexOf(c_exampleUrl);
                if(urlStart != -1 && textBox.Text.Length > urlStart + c_exampleUrl.Length)
                {
                    // +7 -7 so we don't selected the http://
                    textBox.SelectionStart = urlStart + 7;
                    textBox.SelectionLength = c_exampleUrl.Length - 7;
                }
            }

            // If we have example text try to select it
            if (hasExampleText)
            {
                // Note we could accidentally select the word "example" anywhere in the text box...
                // but that's ok for now.
                int exampleStart = textBox.Text.IndexOf(c_exampleText);
                if (exampleStart != -1 && textBox.Text.Length > exampleStart + c_exampleText.Length)
                {
                    textBox.SelectionStart = exampleStart;
                    textBox.SelectionLength = c_exampleText.Length;
                }
            }            
        }
예제 #7
0
        /// <summary>
        ///     Generates a new task panel
        /// </summary>
        /// <param name="cl">Class to generate it for</param>
        /// <param name="parent">ListView associated with the class</param>
        /// <param name="task">Task to add</param>
        /// <returns>A new ListViewItem for the task</returns>
        public static ListViewItem GenerateTaskPanel(Class cl, ListView parent, Task task)
        {
            #region Containers

            // Create the content area
            Grid content = new Grid
            {
                Margin = new Thickness(0),
                Height = 75,
                Background = MainPage.LightGrayBrush,
                Tag = "Task"
            };

            // Create the list of content items and a delegate to add them to the list
            List<UIElement> contentItems = new List<UIElement>();
            Action<UIElement> registerItem = i => { contentItems.Add(i); };

            // The main ListViewItem
            ListViewItem panel = new ListViewItem
            {
                Background = MainPage.TransparentBrush,
                Margin = new Thickness(0, 0, 0, 5),
                Height = 75,
                Tag = false, // Is Panel Expanded
                HorizontalContentAlignment = HorizontalAlignment.Stretch,
                VerticalContentAlignment = VerticalAlignment.Top,
                Padding = new Thickness(0),
                BorderBrush = MainPage.MediumGrayBrush,
                BorderThickness = new Thickness(1),
            };

            #endregion

            #region Title

            // Task title
            TextBlock title = new TextBlock
            {
                Text = task.Title.Trim(),
                TextAlignment = TextAlignment.Left,
                FontSize = 25,
                Foreground = MainPage.BlueBrush,
                Margin = new Thickness(5, 0, 0, 0)
            };
            // Sizing
            title.Measure(new Size(0, 0));
            title.Arrange(new Rect(0, 0, 0, 0));
            registerItem(title);

            #endregion

            #region Finish Button

            // The check mark that marks the task as completed
            Button finish = new Button
            {
                FontFamily = Icons.IconFont,
                Content = task.Complete == 1 ? Icons.Cancel : Icons.Accept,
                Margin = new Thickness(title.ActualWidth + 5, 5, 0, 0),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                Background = MainPage.TransparentBrush
            };

            // Remove the task when the button is pressed
            finish.Tapped += (sender, args) => { TaskList.RemoveTask(cl, parent, panel, task); };
            registerItem(finish);

            #endregion

            #region Info Box

            // Info box
            TextBox info = new TextBox
            {
                TextAlignment = TextAlignment.Left,
                Foreground = new SolidColorBrush(Color.FromArgb(255, 50, 50, 50)),
                HorizontalAlignment = HorizontalAlignment.Left,
                TextWrapping = TextWrapping.Wrap,
                BorderThickness = new Thickness(0),
                AcceptsReturn = true,
                Width = parent.Width / 3 + 25,
                Tag = false, // Edit mode
                IsReadOnly = true, // Edit mode property
                Background = MainPage.TransparentBrush, // Edit mode property
                IsHitTestVisible = false // Edit mode property
            };

            // Add the text - only works if you append each character
            foreach (char c in task.Info)
            {
                info.Text += c.ToString();
            }

            // Border around the info box
            Border infoBorder = new Border
            {
                Child = info,
                Background = MainPage.MediumGrayBrush,
                Margin = new Thickness(5, 36, 0, 7),
                HorizontalAlignment = HorizontalAlignment.Left,
                BorderThickness = new Thickness(0),
                Padding = new Thickness(0)
            };
            registerItem(infoBorder);

            // Edit button for the info box
            Button edit = new Button
            {
                FontFamily = Icons.IconFont,
                Content = Icons.Edit,
                Width = 20,
                Height = 20,
                FontSize = 10,
                Padding = new Thickness(0),
                Background = MainPage.TransparentBrush,
                VerticalAlignment = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(parent.Width / 3 + 10, 36, 0, 7)
            };

            // Toggles edit mode for the info box
            edit.Click += (sender, args) =>
            {
                if (!(bool) info.Tag)
                {
                    info.Tag = true;
                    edit.Content = Icons.Save;
                    info.IsReadOnly = false;
                    info.Background = new SolidColorBrush(Colors.White);
                    info.IsHitTestVisible = true;
                    info.Focus(FocusState.Pointer);
                    info.SelectionStart = info.Text.Length;
                    info.SelectionLength = 0;
                } else
                {
                    info.Tag = false;
                    edit.Content = Icons.Edit;
                    info.IsReadOnly = true;
                    info.Background = MainPage.MediumGrayBrush;
                    info.IsHitTestVisible = false;
                    DataHandler.EditTask(task.Id, "Info", info.Text);
                }
            };
            registerItem(edit);

            #endregion

            #region Circular Progress Bar

            // Progress bar background (gray)
            CircularProgressBar progressBack = new CircularProgressBar
            {
                Percentage = 100,
                SegmentColor = MainPage.MediumGrayBrush,
                Radius = 30,
                StrokeThickness = 5,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Top,
                Margin = new Thickness(0, 2.75, 2.75 + 30, 0)
            };
            registerItem(progressBack);

            // Progress bar foreground (blue)
            CircularProgressBar progressFront = new CircularProgressBar
            {
                Percentage = 0,
                SegmentColor = MainPage.BlueBrush,
                Radius = 30,
                StrokeThickness = 5,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Top,
                Margin = new Thickness(0, 2.75, 2.75 + 30, 0),
                Transitions = new TransitionCollection()
            };
            registerItem(progressFront);

            // Text inside the progress bar that shows the time remaining
            TextBlock timeLeft = new TextBlock
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Text = string.Empty,
                FontSize = 12,
                Foreground = MainPage.BlueBrush,
                TextAlignment = TextAlignment.Center
            };

            // Helps with alignment for the progress bar
            Border border = new Border
            {
                BorderBrush = MainPage.BlueBrush,
                BorderThickness = new Thickness(0),
                Child = timeLeft,
                Height = 70,
                Width = 70,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Top,
                Margin = progressFront.Margin
            };
            registerItem(border);

            // Delegate for
            Action updateProgress = () =>
            {
                // Clamp the progress to 100%
                progressFront.Percentage = Math.Min(Util.GetPercentTime(task) * 100, 100);

                // Finished tasks get an orange color
                bool finished = false;
                if (progressFront.Percentage.Equals(100.0))
                {
                    finished = true;
                    progressFront.SegmentColor = MainPage.OrangeRedBrush;
                    timeLeft.Foreground = MainPage.OrangeRedBrush;
                }

                // Set the new text
                timeLeft.Text = $"{Util.GetTimeString(task)}{(finished ? " ago" : string.Empty)}";
            };
            updateProgress();

            // Update the progress every second
            ThreadPoolTimer.CreatePeriodicTimer(
                async poolTimer =>
                {
                    await progressFront.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { updateProgress(); });
                },
                new TimeSpan(0, 0, 0, 1));

            #endregion

            #region Assigned/Due Times

            // Assigned/due info
            RichTextBlock timeInfo = new RichTextBlock
            {
                FontSize = 14,
                Margin = new Thickness(-5),
                TextAlignment = TextAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Stretch,
                TextWrapping = TextWrapping.NoWrap
            };

            // "Assigned on" and "Due on" text
            // Separated with different colors
            Run assignedText = new Run
            {
                Text = "Assigned: ",
                Foreground = MainPage.BlueBrush
            };

            Run assignedDate = new Run
            {
                Text = $"{task.AssignedOn}",
                Foreground = MainPage.GreenBrush
            };

            Run dueText = new Run
            {
                Text = "Due: ",
                Foreground = MainPage.BlueBrush
            };

            Run dueDate = new Run
            {
                Text = $"{task.DueOn}",
                Foreground = MainPage.OrangeRedBrush
            };

            // Set up lines
            Paragraph p1 = new Paragraph();
            p1.Inlines.Add(assignedText);
            p1.Inlines.Add(assignedDate);

            Paragraph p2 = new Paragraph();
            p2.Inlines.Add(dueText);
            p2.Inlines.Add(dueDate);

            // Add the info to the text box
            timeInfo.Blocks.Add(p1);
            timeInfo.Blocks.Add(p2);

            // Container for time info
            Border timeInfoBorder = new Border
            {
                Child = timeInfo,
                BorderBrush = MainPage.BlueBrush,
                BorderThickness = new Thickness(0),
                Margin = new Thickness(parent.Width / 3 + 35, 36, 105, 5),
                Padding = new Thickness(0),
                VerticalAlignment = VerticalAlignment.Stretch
            };
            registerItem(timeInfoBorder);

            #endregion

            #region Expand Button

            // Button that expands the box
            Button expand = new Button
            {
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Top,
                Height = 73,
                Width = 25,
                Margin = new Thickness(0, 0, 0, 0),
                Content = Icons.Down,
                FontFamily = Icons.IconFont,
                Padding = new Thickness(0)
            };

            // This makes sure all other task panels collapse smoothly if a new one is opened
            expand.Tapped += (sender, args) =>
            {
                // Get the new height based on the tag that tells you if the panel is open or closed
                int to = !(bool) panel.Tag ? 412 : 75;

                // Set the new button content to the opposite arrow
                expand.Content = !(bool) panel.Tag ? Icons.Up : Icons.Down;

                // If the panel is not opened
                if (!(bool) panel.Tag)
                {
                    // For each task that is open and has content
                    foreach (ListViewItem item in parent.Items.Cast<ListViewItem>()
                        .Where(item => (bool?) item.Tag ?? false && item.Content != null))
                    {
                        // If the grid content is not null and the grid tag is not null
                        if (!((item.Content as Grid)?.Tag as bool? ?? false))
                        {
                            // Find the button in the grid that has the Up icon
                            foreach (Button btn in (item.Content as Grid).Children.OfType<Button>()
                                .Where(btn => (string) btn.Content == Icons.Up))
                            {
                                // ... And change it to the down icon
                                btn.Content = Icons.Down;
                            }

                            // Collapse the panel
                            Util.CreateAnimation(150, item, null, 75, "Height").Begin();

                            // Set the tag to false indicating the panel is closed
                            item.Tag = false;
                        }
                    }
                }

                // Once all other panels have been collapsed, expand the new one
                Util.CreateAnimation(150, panel, null, to, "Height").Begin();

                // Set its tag appropriately
                panel.Tag = !(bool) panel.Tag;
            };

            registerItem(expand);

            #endregion

            #region Calendar

            // Calendar showing date assigned, date due, today
            CalendarView calendar = new CalendarView
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Top,
                SelectionMode = CalendarViewSelectionMode.None,
                BlackoutForeground = new SolidColorBrush(Colors.White),
                Background = MainPage.MediumGrayBrush,
                CalendarItemBackground = MainPage.TransparentBrush,
                BorderBrush = MainPage.TransparentBrush,
                CalendarItemBorderBrush = MainPage.TransparentBrush,
                OutOfScopeBackground = MainPage.TransparentBrush,
                OutOfScopeForeground = new SolidColorBrush(Colors.Gray),
                Margin = new Thickness(parent.Width / 3 + 35, 75, 3, 5),
            };

            // Override item rendering to change colors
            calendar.CalendarViewDayItemChanging += (sender, args) =>
            {
                if (args.Item == null)
                {
                    return;
                }
                DateTime day = args.Item.Date.DateTime;
                if (day.Date == DateTime.Parse(task.AssignedOn.ToString()).Date)
                {
                    args.Item.Background = MainPage.GreenBrush;
                    args.Item.IsBlackout = true; // Hack to change the foreground color
                } else if (day.Date == DateTime.Parse(task.DueOn.ToString()).Date)
                {
                    args.Item.Background = MainPage.OrangeRedBrush;
                    args.Item.IsBlackout = true;
                }
                if (day.Date == DateTime.Today)
                {
                    args.Item.IsBlackout = false;
                }
            };
            calendar.SetDisplayDate(DateTime.Today);
            registerItem(calendar);

            #endregion

            #region Sizing and Creation

            // Sizing
            parent.SizeChanged += (sender, args) =>
            {
                info.Width = args.NewSize.Width / 3 + 25;
                edit.Margin = new Thickness(args.NewSize.Width / 3 + 10, 36, 0, 7);
                calendar.Margin = new Thickness(args.NewSize.Width / 3 + 35, 75, 3, 5);
                timeInfoBorder.Margin = new Thickness(args.NewSize.Width / 3 + 35, 36, 105, 5);
            };

            panel.SizeChanged += (sender, args) => { content.Height = args.NewSize.Height; };

            // Add each element in the contentItems list
            foreach (UIElement element in contentItems)
            {
                content.Children.Add(element);
            }

            // Set the container content
            panel.Content = content;

            return panel;

            #endregion
        }
        /// <summary>
        /// Preforms the selected edit type on the text box given.
        /// </summary>
        /// <param name="textBox"></param>
        /// <param name="editType"></param>
        public static void DoEdit(TextBox textBox, VisualHelperTypes editType)
        {
            // First refocus the text box since the user clicked a button.
            // We need to do this quickly so the virt keyboard doesn't move.
            textBox.Focus(FocusState.Programmatic);

            // Get some vars
            int selStart = textBox.SelectionStart;
            int selLength = textBox.SelectionLength;
            int newLineSelOffset = 0;
            string curText = textBox.Text;
            string insertNewLine = null;
            string insertAtEnd = null;
            bool isLink = false;
            bool hasExampleText = false;

            // For some reason the SelectionStart count /r/n as 1 instead of two. So add one for each /r/n we find.
            for(int count = 0; count < selStart + newLineSelOffset; count++)
            {
                if(curText[count] == '\r' && count + 1 < curText.Length && curText[count + 1] == '\n')
                {
                    newLineSelOffset++;
                }
            }

            // Depending on the type see what we can do.
            switch (editType)
            {
                case HelperControls.VisualHelperTypes.Bold:
                    if (selLength != 0)
                    {
                        // Wrap the selected text
                        textBox.Text = curText.Insert(selStart + newLineSelOffset + selLength, "**").Insert(selStart + newLineSelOffset, "**");
                    }
                    else
                    {
                        // Or add to the end
                        insertAtEnd = $"**{c_exampleText}**";
                        hasExampleText = true;
                    }
                    break;
                case HelperControls.VisualHelperTypes.Italic:
                    if (selLength != 0)
                    {
                        // Wrap the selected text
                        textBox.Text = curText.Insert(selStart + newLineSelOffset + selLength, "*").Insert(selStart + newLineSelOffset, "*");
                    }
                    else
                    {
                        // Or add to the end
                        insertAtEnd = $"*{c_exampleText}*";
                        hasExampleText = true;
                    }
                    break;
                case HelperControls.VisualHelperTypes.Link:
                    if (selLength != 0)
                    {
                        // Wrap the selected text
                        textBox.Text = curText.Insert(selStart + newLineSelOffset + selLength, $"]({c_exampleUrl})").Insert(selStart + newLineSelOffset, "[");
                    }
                    else
                    {
                        // Or add to the end
                        insertAtEnd = $"[{c_exampleText}]({c_exampleUrl})";
                    }
                    isLink = true;
                    break;
                case HelperControls.VisualHelperTypes.NewLine:
                    int injectPos = selStart + newLineSelOffset;
                    // Inject the new line at the current pos
                    textBox.Text = curText.Insert(injectPos, "  \r\n");
                    // Move the selection to the end of insert
                    textBox.SelectionStart = injectPos + 3 - newLineSelOffset;
                    break;
                case HelperControls.VisualHelperTypes.Quote:
                    insertNewLine = "> ";
                    break;
                case HelperControls.VisualHelperTypes.List:
                    insertNewLine = "* ";
                    break;
                case HelperControls.VisualHelperTypes.NumberedList:
                    insertNewLine = "1. ";
                    break;
                case HelperControls.VisualHelperTypes.Code:
                    insertNewLine = "    ";
                    break;

            }

            // If the insert on new line is not null we need to find the last new line and
            // insert the text.
            if (insertNewLine != null)
            {
                // Search for a new line.
                int offsetSelStart = selStart + newLineSelOffset;
                int searchStart = offsetSelStart == curText.Length ? offsetSelStart - 1 : offsetSelStart;

                // Try to find it the new line before the cursor
                int indexLastNewLine = curText.LastIndexOf('\n', searchStart);

                // We need to make sure there are two new lines before this block
                int searchNewlineCount = indexLastNewLine - 1;
                while (searchNewlineCount > 0)
                {
                    // If we find an /r just move on.
                    if(curText[searchNewlineCount] == '\r')
                    {
                        searchNewlineCount--;
                        continue;
                    }
                    // If we find an /n we are good.
                    else if (curText[searchNewlineCount] == '\n')
                    {
                        break;
                    }
                    // If it is anything else we need to add it.
                    else
                    {
                        insertNewLine = "\r\n" + insertNewLine;
                        break;
                    }
                }

                // Insert the text
                textBox.Text = curText.Insert(indexLastNewLine + 1, insertNewLine);

                // If where we ended up inserting was after where the selection was move it to the end.
                if(indexLastNewLine == -1 || (offsetSelStart + insertNewLine.Length) < indexLastNewLine)
                {
                    textBox.SelectionStart = offsetSelStart - newLineSelOffset + insertNewLine.Length;
                }
                else
                {
                    // If not move it back to where it was + our what we inserted.
                    textBox.SelectionStart = selStart + insertNewLine.Length;
                }
            }

            // If this isn't null we have something to add at the end of the current text.
            if (insertAtEnd != null)
            {
                // If the last char isn't a space add one.
                if (textBox.Text.Length > 0 && !Char.IsWhiteSpace(textBox.Text[textBox.Text.Length - 1]))
                {
                    textBox.Text += ' ';
                }
                textBox.Text += insertAtEnd;
                textBox.SelectionStart = textBox.Text.Length;
            }

            // If we added a link try to select the example url
            if (isLink)
            {
                int urlStart = textBox.Text.LastIndexOf(c_exampleUrl);
                if(urlStart != -1 && textBox.Text.Length > urlStart + c_exampleUrl.Length)
                {
                    // +7 -7 so we don't selected the http://
                    textBox.SelectionStart = urlStart + 7 - newLineSelOffset;
                    textBox.SelectionLength = c_exampleUrl.Length - 7;
                }
            }

            // If we have example text try to select it
            if (hasExampleText)
            {
                // Note we could accidentally select the word "example" anywhere in the text box...
                // but that's ok for now.
                int exampleStart = textBox.Text.LastIndexOf(c_exampleText);
                if (exampleStart != -1 && textBox.Text.Length > exampleStart + c_exampleText.Length)
                {
                    textBox.SelectionStart = exampleStart - newLineSelOffset;
                    textBox.SelectionLength = c_exampleText.Length;
                }
            }
        }
        /// <summary>
        /// Shows the dialog. It takes <see cref="InputDialogViewModel"/> to populate the system dialog. It also sets the first command to be 
        /// the default and last one to be the cancel command.
        /// </summary>
        /// <param name="viewType"> Type of dialog control. </param>
        public async void Show(Type viewType)
        {
            this.Initialize();

            var dialog = new ContentDialog
            {
                Title = this.ViewModel.ActivationData.Title,
                MaxWidth = Window.Current.CoreWindow.Bounds.Width
            };

            var panel = new StackPanel();
            panel.Children.Add(new TextBlock
            {
                Text = this.ViewModel.ActivationData.Message,
                TextWrapping = TextWrapping.Wrap,
                Margin = new Thickness(0, 6, 0, 12)
            });

            var tb = new TextBox
            {
                Text = this.ViewModel.ActivationData.Text
            };

            panel.Children.Add(tb);
            
            var primaryText = this.ViewModel.ActivationData.Commands.FirstOrDefault() ?? "Ok";
            var secondaryText = this.ViewModel.ActivationData.Commands.Skip(1).FirstOrDefault() ?? string.Empty;
            var returnValue = secondaryText;

            tb.KeyUp += (sender, args) =>
            {
                if (args.Key == VirtualKey.Enter)
                {
                    returnValue = primaryText;
                    dialog.Hide();
                }
            };

            dialog.Content = panel;
            dialog.PrimaryButtonText = primaryText;
            dialog.SecondaryButtonText = secondaryText;

            tb.SelectionStart = tb.Text.Length;
            tb.Focus(FocusState.Programmatic);

            try
            {
                this.dialogTask = dialog.ShowAsync();
                var result = await this.dialogTask;
                var resultValue = string.Empty;

                this.dialogTask = null;
                switch (result)
                {
                    case ContentDialogResult.None:
                        resultValue = returnValue;
                        break;
                    case ContentDialogResult.Primary:
                        resultValue = primaryText;
                        break;
                    case ContentDialogResult.Secondary:
                        resultValue = secondaryText;
                        break;
                }

                await this.NavigationService.GoBackAsync(new InputDialogResult(resultValue, tb.Text));
            }
            catch (TaskCanceledException ex)
            {
                // Happens when you call nanavigationSerivce.GoBack(...) while the dialog is still open.
            }
        }