private void UpdateWidgets(UpdateCause cause)
        {
            if (_currentBlock != null)
            {
                // Update size and position
                var   rectangle = _currentBlock.Box;
                float paddingLeft, paddingRight;
                GetBlockPadding(_currentBlock, out paddingLeft, out paddingRight);
                var transform = _editor.Renderer.GetViewTransform();
                var topLeft   = transform.Apply(rectangle.X + paddingLeft, rectangle.Y);
                var topRight  = transform.Apply(rectangle.X + rectangle.Width - paddingRight, rectangle.Y);
                var x         = topLeft.X;
                var y         = topLeft.Y;
                var width     = topRight.X - topLeft.X;

                Width  = width;
                Margin = new Thickness(Math.Floor(x), Math.Floor(y - ActualHeight), 0, 0);

                // Update text
                Label lastUpdatedItem = null;
                {
                    textItem.Children.Clear();

                    foreach (var word in _currentWords)
                    {
                        var label = word.Label;
                        label = label.Replace('\n', ' ');

                        var item = new Label {
                            Content                    = label,
                            HorizontalAlignment        = HorizontalAlignment.Left,
                            VerticalAlignment          = VerticalAlignment.Stretch,
                            HorizontalContentAlignment = HorizontalAlignment.Left,
                            VerticalContentAlignment   = VerticalAlignment.Center,
                            Padding                    = new Thickness(0),
                            BorderThickness            = new Thickness(0),
                            Margin     = new Thickness(0),
                            Background = Brushes.Transparent
                        };

                        if (word.Updated)
                        {
                            item.Foreground = new SolidColorBrush(SMART_GUIDE_TEXT_HIGHLIGHT_COLOR);
                        }
                        else
                        {
                            item.Foreground = new SolidColorBrush(SMART_GUIDE_TEXT_DEFAULT_COLOR);
                        }

                        textItem.Children.Add(item);

                        if (word.Updated)
                        {
                            lastUpdatedItem = item;
                        }
                    }
                }

                // Set cursor position
                if (lastUpdatedItem != null)
                {
                    lastUpdatedItem.BringIntoView();
                }
                else
                {
                    scrollItem.ScrollToLeftEnd();
                }

                // Update Style item
                SetTextBlockStyle(TextBlockStyle.NORMAL);

                // Visibility/Fading
                {
                    int delay = 0;

                    if (cause == UpdateCause.Edit)
                    {
                        delay = _currentBlock.Id.StartsWith("diagram/") ? fadeOutWriteInDiagramDelay : fadeOutWriteDelay;
                    }
                    else
                    {
                        delay = fadeOutOtherDelay;
                    }

                    if (cause != UpdateCause.View)
                    {
                        _timer1.Stop();

                        if (delay > 0)
                        {
                            _timer1.Interval = TimeSpan.FromMilliseconds(delay);
                            _timer1.Start();
                        }

                        this.Visibility = Visibility.Visible;
                    }

                    if (lastUpdatedItem != null)
                    {
                        _timer2.Interval = TimeSpan.FromMilliseconds(removeHighlightDelay);
                        _timer2.Start();
                    }
                }
            }
            else
            {
                _timer1.Stop();
                ResetWidgets();
            }
        }
        private void UpdateWidgets(UpdateCause cause)
        {
            if (_currentBlock != null)
            {
                // Update size and position
                var   rectangle = _currentBlock.Box;
                float paddingLeft, paddingRight;
                GetBlockPadding(_currentBlock, out paddingLeft, out paddingRight);
                var transform = _editor.Renderer.GetViewTransform();
                var topLeft   = transform.Apply(rectangle.X + paddingLeft, rectangle.Y);
                var topRight  = transform.Apply(rectangle.X + rectangle.Width - paddingRight, rectangle.Y);
                var x         = topLeft.X;
                var y         = topLeft.Y;
                var width     = topRight.X - topLeft.X;
                var yOffset   = (ActualHeight > 0) ? ActualHeight : SMART_GUIDE_SIZE; // ActualHeight may be zero if control was collapsed

                Width  = width;
                Margin = new Thickness(x, y - yOffset, 0, 0);

                TextBlock lastUpdatedItem = null;
                if ((cause == UpdateCause.Edit) || (cause == UpdateCause.Selection))
                {
                    // Update text
                    textItem.Children.Clear();

                    foreach (var word in _currentWords)
                    {
                        var label = word.Label;
                        label = label.Replace('\n', ' ');

                        var item = new TextBlock {
                            Text = label,
                            HorizontalAlignment = HorizontalAlignment.Left,
                            VerticalAlignment   = VerticalAlignment.Stretch,
                            TextAlignment       = TextAlignment.Left,
                            TextWrapping        = TextWrapping.NoWrap,
                            Padding             = new Thickness(0),
                            Margin   = new Thickness(0),
                            MinWidth = 3,
                        };

                        if (word.Updated)
                        {
                            item.Foreground = new SolidColorBrush(SMART_GUIDE_TEXT_HIGHLIGHT_COLOR);
                        }
                        else
                        {
                            item.Foreground = new SolidColorBrush(SMART_GUIDE_TEXT_DEFAULT_COLOR);
                        }

                        textItem.Children.Add(item);

                        if (word.Updated)
                        {
                            lastUpdatedItem = item;
                        }
                    }
                }

                // Set cursor position
                if (lastUpdatedItem != null)
                {
                    // Delay the scroll because the item's position/size within the scrollViewer are not updated yet
                    Windows.System.Threading.ThreadPoolTimer.CreateTimer
                    (
                        async(source) =>
                    {
                        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                        {
                            var tr  = lastUpdatedItem.TransformToVisual((UIElement)scrollItem.Content);
                            var pos = tr.TransformPoint(new Point(0, 0));
                            scrollItem.ChangeView(pos.X, 0.0, 1.0f, true);
                        });
                    },
                        TimeSpan.FromMilliseconds(10)
                    );
                }

                // Update Style item
                SetTextBlockStyle(TextBlockStyle.NORMAL);

                // Visibility/Fading
                {
                    int delay = 0;

                    if (cause == UpdateCause.Edit)
                    {
                        delay = _currentBlock.Id.StartsWith("diagram/") ? fadeOutWriteInDiagramDelay : fadeOutWriteDelay;
                    }
                    else
                    {
                        delay = fadeOutOtherDelay;
                    }

                    if (cause != UpdateCause.View)
                    {
                        _timer1.Stop();

                        if (delay > 0)
                        {
                            _timer1.Interval = TimeSpan.FromMilliseconds(delay);
                            _timer1.Start();
                        }

                        this.Visibility = Windows.UI.Xaml.Visibility.Visible;
                    }

                    if (lastUpdatedItem != null)
                    {
                        _timer2.Interval = TimeSpan.FromMilliseconds(removeHighlightDelay);
                        _timer2.Start();
                    }
                }
            }
            else
            {
                _timer1.Stop();
                ResetWidgets();
            }
        }