Ejemplo n.º 1
0
        public void SetFormattedText_ValidXmlWithSupportedChildNode_ConvertToInlines()
        {
            // Setup
            const string xmlToConvert = "<text>test <bold>bold text</bold></text>";
            var          textBlock    = new TextBlock();

            // Precondition
            CollectionAssert.IsEmpty(textBlock.Inlines);

            // Call
            TextBlockExtensions.SetFormattedText(textBlock, xmlToConvert);

            // Assert
            Assert.AreEqual(1, textBlock.Inlines.Count);
            var span = (Span)textBlock.Inlines.First();

            Inline[] spanInlines = span.Inlines.ToArray();

            Assert.AreEqual(2, spanInlines.Length);
            var run = (Run)spanInlines[0];

            Assert.AreEqual("test ", run.Text);

            var bold     = (Bold)spanInlines[1];
            var boldSpan = (Span)bold.Inlines.First();

            Assert.AreEqual("bold text", ((Run)boldSpan.Inlines.First()).Text);
        }
Ejemplo n.º 2
0
        public void GetFormattedText_DefaultValue_ReturnNull()
        {
            // Setup
            var textBlock = new TextBlock();

            // Call
            string formattedText = TextBlockExtensions.GetFormattedText(textBlock);

            // Assert
            Assert.IsNull(formattedText);
        }
Ejemplo n.º 3
0
        public void GetFormattedText_TextSet_ReturnText()
        {
            // Setup
            const string xmlToConvert = "<text>test <bold>bold text</bold></text>";
            var          textBlock    = new TextBlock();

            TextBlockExtensions.SetFormattedText(textBlock, xmlToConvert);

            // Call
            string formattedText = TextBlockExtensions.GetFormattedText(textBlock);

            // Assert
            Assert.AreEqual(xmlToConvert, formattedText);
        }
Ejemplo n.º 4
0
        public void SetFormattedText_ValidXmlWithoutChildNodes_ConvertToInlines()
        {
            // Setup
            const string xmlToConvert = "<text>test</text>";
            var          textBlock    = new TextBlock();

            // Precondition
            CollectionAssert.IsEmpty(textBlock.Inlines);

            // Call
            TextBlockExtensions.SetFormattedText(textBlock, xmlToConvert);

            // Assert
            Assert.AreEqual(1, textBlock.Inlines.Count);
            var span = (Span)textBlock.Inlines.First();

            Assert.AreEqual(1, span.Inlines.Count);
            var run = (Run)span.Inlines.First();

            Assert.AreEqual("test", run.Text);
        }
Ejemplo n.º 5
0
        public void GivenTextBlockWithXml_WhenNewTextXmlNull_ThenInlinesCleared()
        {
            // Given
            const string xmlToConvert = "<text>test</text>";
            var          textBlock    = new TextBlock();

            TextBlockExtensions.SetFormattedText(textBlock, xmlToConvert);

            // Precondition
            Assert.AreEqual(1, textBlock.Inlines.Count);
            var span = (Span)textBlock.Inlines.First();

            Assert.AreEqual(1, span.Inlines.Count);
            var run = (Run)span.Inlines.First();

            Assert.AreEqual("test", run.Text);

            // When
            TextBlockExtensions.SetFormattedText(textBlock, null);

            // Then
            CollectionAssert.IsEmpty(textBlock.Inlines);
        }
Ejemplo n.º 6
0
 public NewDiplomacyScreen()
 {
     TextBlockExtensions.AddHyperlinkClickedHandler(this, OnMessageParameterLinkClick);
     InitializeComponent();
 }
            public MyScheduleItem(ViewItemSchedule s)
            {
                ViewItemClass c = s.Class as ViewItemClass;

                base.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top;
                base.Background        = new SolidColorBrush(ColorTools.GetColor(c.Color));

                var timeSpan     = s.EndTime.TimeOfDay - s.StartTime.TimeOfDay;
                var hours        = timeSpan.TotalHours;
                var showTimeText = timeSpan.TotalMinutes >= 38;

                base.Height = Math.Max(HEIGHT_OF_HOUR * hours, 0);

                base.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                base.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                base.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(1, GridUnitType.Star)
                });

                base.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = GridLength.Auto
                });
                base.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(1, GridUnitType.Star)
                });

                TextBlock tbClass = new TextBlock()
                {
                    Text         = c.Name,
                    Style        = Application.Current.Resources["BaseTextBlockStyle"] as Style,
                    Foreground   = Brushes.White,
                    FontWeight   = FontWeights.SemiBold,
                    Margin       = new Windows.UI.Xaml.Thickness(6, 0, 6, 0),
                    TextWrapping = Windows.UI.Xaml.TextWrapping.NoWrap,
                    FontSize     = 14
                };

                Grid.SetColumnSpan(tbClass, 2);
                base.Children.Add(tbClass);

                // Add the time text (xx:xx to xx:xx) - do NOT show the date text for anything below 38 minutes as that will overlap with the title and get pushed beneath it.
                TextBlock tbTime = null;

                if (showTimeText)
                {
                    var timeFormatter = new DateTimeFormatter("shorttime");
                    tbTime = new TextBlock()
                    {
                        Text         = LocalizedResources.Common.GetStringTimeToTime(timeFormatter.Format(s.StartTime), timeFormatter.Format(s.EndTime)),
                        Style        = Application.Current.Resources["BaseTextBlockStyle"] as Style,
                        Foreground   = Brushes.White,
                        FontWeight   = FontWeights.SemiBold,
                        Margin       = new Windows.UI.Xaml.Thickness(6, -2, 6, 0),
                        TextWrapping = Windows.UI.Xaml.TextWrapping.NoWrap,
                        FontSize     = 14
                    };
                }

                TextBlock tbRoom = new TextBlock()
                {
                    Style        = Application.Current.Resources["BaseTextBlockStyle"] as Style,
                    Foreground   = Brushes.White,
                    FontWeight   = FontWeights.SemiBold,
                    Margin       = new Windows.UI.Xaml.Thickness(6, -2, 6, 0),
                    TextWrapping = Windows.UI.Xaml.TextWrapping.WrapWholeWords,
                    FontSize     = 14
                };

                TextBlockExtensions.SetHyperlinkColor(tbRoom, Brushes.White);
                TextBlockExtensions.SetRawText(tbRoom, s.Room);

                if (hours >= 1.1)
                {
                    if (showTimeText)
                    {
                        Grid.SetRow(tbTime, 1);
                        Grid.SetColumnSpan(tbTime, 2);
                        base.Children.Add(tbTime);
                    }

                    if (!string.IsNullOrWhiteSpace(s.Room))
                    {
                        Grid.SetRow(tbRoom, showTimeText ? 2 : 1);
                        Grid.SetColumnSpan(tbRoom, 2);
                        base.Children.Add(tbRoom);
                    }
                }

                else
                {
                    if (showTimeText)
                    {
                        tbTime.Margin            = new Thickness(tbTime.Margin.Left, tbTime.Margin.Top, tbTime.Margin.Right, 8);
                        tbTime.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Bottom;
                        Grid.SetRow(tbTime, 2);
                        base.Children.Add(tbTime);
                    }

                    tbRoom.Margin            = new Thickness(tbRoom.Margin.Left, tbRoom.Margin.Top, tbRoom.Margin.Right, 8);
                    tbRoom.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Bottom;
                    tbRoom.TextAlignment     = TextAlignment.Right;
                    tbRoom.TextWrapping      = TextWrapping.NoWrap;
                    tbRoom.TextTrimming      = TextTrimming.CharacterEllipsis;
                    Grid.SetRow(tbRoom, showTimeText ? 2 : 1);
                    Grid.SetColumn(tbRoom, 1);
                    base.Children.Add(tbRoom);
                }
            }