Ejemplo n.º 1
0
        private static void RecreateInlines(TextBlock t, Inline prefix, IEnumerable<Inline> list)
        {
            t.Inlines.Clear();

            if (prefix != null)
                t.Inlines.Add(prefix);
            foreach (var i in list)
            {
                t.Inlines.Add(i);
            }

            t.InvalidateMeasure();
        }
Ejemplo n.º 2
0
		public void ArrangeTooLongLocal_LineWrapMeasureReverseTest ()
		{
			Border b = new Border ();
			TextBlock tb = new TextBlock ();
			tb.TextWrapping = TextWrapping.Wrap;
			
			b.Child = tb;
			tb.Width = 44;
			tb.Text = "Hello and don't you forget Who I am";

			Assert.IsTrue (tb.ActualWidth > 32 && tb.ActualWidth < 34, "1. textblock.ActualWidth is " + tb.ActualWidth.ToString ());
			Assert.AreEqual (7, GetLineCount (tb.ActualHeight), "1. line count based on textblock.ActualHeight");
			//Assert.AreEqual (112, tb.ActualHeight, "1. tb.ActualHeight");
			
			//Console.WriteLine ("=========== Calling Border.Measure() ============");
			b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
			//Console.WriteLine ("========= Done calling Border.Measure() =========");
			
			// FIXME: wrong after this point
			
			Assert.IsTrue (tb.ActualWidth < 10.9 && tb.ActualWidth > 10.8, "2. textblock.ActualWidth is " + tb.ActualWidth.ToString ());
			Assert.AreEqual (28, GetLineCount (tb.ActualHeight), "2. line count based on textblock.ActualHeight");
			//Assert.AreEqual (560, tb.ActualHeight, "2. tb.ActualHeight");

			tb.Text = "Hello and don't you forget Who I am.";

			Assert.IsTrue (tb.ActualWidth < 10.9 && tb.ActualWidth > 10.8, "3. textblock.ActualWidth is " + tb.ActualWidth.ToString ());
			Assert.AreEqual (29, GetLineCount (tb.ActualHeight), "3. line count based on textblock.ActualHeight");
			//Assert.AreEqual (576, tb.ActualHeight, "3. tb.ActualHeight");

			tb.Width = 70;
			b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));

			Assert.IsTrue (tb.ActualWidth < 10.9 && tb.ActualWidth > 10.8, "4. textblock.ActualWidth is " + tb.ActualWidth.ToString ());
			Assert.AreEqual (29, GetLineCount (tb.ActualHeight), "4. line count based on textblock.ActualHeight");
			//Assert.AreEqual (576, tb.ActualHeight, "4. tb.ActualHeight");

			b.InvalidateMeasure ();
			tb.InvalidateMeasure ();

			b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
			
			Assert.IsTrue (tb.ActualWidth < 10.9 && tb.ActualWidth > 10.8, "5. textblock.ActualWidth is " + tb.ActualWidth.ToString ());
			Assert.AreEqual (29, GetLineCount (tb.ActualHeight), "5. line count based on textblock.ActualHeight");
			//Assert.AreEqual (576, tb.ActualHeight, "5. tb.ActualHeight");
		}
Ejemplo n.º 3
0
        // return the dimension of the text after aplying styles from given textblock
        private Point getTextWidthHeight(string text, TextBlock itemTextTB)
        {
            TextBlock tb = new TextBlock();
            tb.Text = text;
            tb.Style = itemTextTB.Style;
            tb.FontFamily = itemTextTB.FontFamily;
            tb.FontSize = itemTextTB.FontSize;
            tb.FontSource = itemTextTB.FontSource;
            tb.FontStretch = itemTextTB.FontStretch;
            tb.FontStyle = itemTextTB.FontStyle;
            tb.FontWeight = itemTextTB.FontWeight;
            tb.InvalidateMeasure();

            Point xy = new Point(tb.ActualWidth, tb.ActualHeight);
            return xy;
        }