WPF C# get the size and position of inline element of a TextBlock












0















I use this example ( https://siderite.blogspot.com/2016/03/how-to-draw-outlined-text-in-wpf-and.html#at2665784896 ) for add outline to a text in a TextBlock. However this example don't support Inlines.



I try to add this ability modifying the OnRender and I iterate the Inlines collection to build a Geometry for each Inline block. The problem is that I need to get the position and size of the inline block in the TextBlock instead of those of the whole text in the TextBlock.



This is the source code that I have modified.



protected override void OnRender(DrawingContext drawingContext)
{
ensureTextBlock();
base.OnRender(drawingContext);

foreach (Inline inline in _textBlock.Inlines)
{
var textRange = new TextRange(inline.ContentStart, inline.ContentEnd);
var formattedText = new FormattedText(
textRange.Text,
CultureInfo.CurrentUICulture,
inline.FlowDirection,
new Typeface(inline.FontFamily, inline.FontStyle, inline.FontWeight, inline.FontStretch),
inline.FontSize, System.Windows.Media.Brushes.Black // This brush does not matter since we use the geometry of the text.
);
formattedText.SetTextDecorations(inline.TextDecorations);


//*****************************************************************
//This part get the size and position of the TextBlock
// Instead I need to find a way to get the size and position of the Inline block

//formattedText.TextAlignment = _textBlock.TextAlignment;
//formattedText.Trimming = _textBlock.TextTrimming;

formattedText.LineHeight = _textBlock.LineHeight;
formattedText.MaxTextWidth = _textBlock.ActualWidth - _textBlock.Padding.Left - _textBlock.Padding.Right;
formattedText.MaxTextHeight = _textBlock.ActualHeight - _textBlock.Padding.Top;// - _textBlock.Padding.Bottom;
while (formattedText.Extent == double.NegativeInfinity)
{
formattedText.MaxTextHeight++;
}

// Build the geometry object that represents the text.
var _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(_textBlock.Padding.Left, _textBlock.Padding.Top));

//*****************************************************************


var textPen = new System.Windows.Media.Pen(Stroke, StrokeThickness * 2)
{
DashCap = PenLineCap.Round,
EndLineCap = PenLineCap.Round,
LineJoin = PenLineJoin.Round,
StartLineCap = PenLineCap.Round
};

var boundsGeo = new RectangleGeometry(new Rect(0, 0, ActualWidth, ActualHeight));

_clipGeometry = Geometry.Combine(boundsGeo, _textGeometry, GeometryCombineMode.Exclude, null);
drawingContext.PushClip(_clipGeometry);
drawingContext.DrawGeometry(System.Windows.Media.Brushes.Transparent, textPen, _textGeometry);
drawingContext.Pop();
}
}


I need to change the part that get the size and position from the TextBlock in order to get the size and position of the Inline block, but I don't see any property of Inline that can get that information. Any idea?










share|improve this question





























    0















    I use this example ( https://siderite.blogspot.com/2016/03/how-to-draw-outlined-text-in-wpf-and.html#at2665784896 ) for add outline to a text in a TextBlock. However this example don't support Inlines.



    I try to add this ability modifying the OnRender and I iterate the Inlines collection to build a Geometry for each Inline block. The problem is that I need to get the position and size of the inline block in the TextBlock instead of those of the whole text in the TextBlock.



    This is the source code that I have modified.



    protected override void OnRender(DrawingContext drawingContext)
    {
    ensureTextBlock();
    base.OnRender(drawingContext);

    foreach (Inline inline in _textBlock.Inlines)
    {
    var textRange = new TextRange(inline.ContentStart, inline.ContentEnd);
    var formattedText = new FormattedText(
    textRange.Text,
    CultureInfo.CurrentUICulture,
    inline.FlowDirection,
    new Typeface(inline.FontFamily, inline.FontStyle, inline.FontWeight, inline.FontStretch),
    inline.FontSize, System.Windows.Media.Brushes.Black // This brush does not matter since we use the geometry of the text.
    );
    formattedText.SetTextDecorations(inline.TextDecorations);


    //*****************************************************************
    //This part get the size and position of the TextBlock
    // Instead I need to find a way to get the size and position of the Inline block

    //formattedText.TextAlignment = _textBlock.TextAlignment;
    //formattedText.Trimming = _textBlock.TextTrimming;

    formattedText.LineHeight = _textBlock.LineHeight;
    formattedText.MaxTextWidth = _textBlock.ActualWidth - _textBlock.Padding.Left - _textBlock.Padding.Right;
    formattedText.MaxTextHeight = _textBlock.ActualHeight - _textBlock.Padding.Top;// - _textBlock.Padding.Bottom;
    while (formattedText.Extent == double.NegativeInfinity)
    {
    formattedText.MaxTextHeight++;
    }

    // Build the geometry object that represents the text.
    var _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(_textBlock.Padding.Left, _textBlock.Padding.Top));

    //*****************************************************************


    var textPen = new System.Windows.Media.Pen(Stroke, StrokeThickness * 2)
    {
    DashCap = PenLineCap.Round,
    EndLineCap = PenLineCap.Round,
    LineJoin = PenLineJoin.Round,
    StartLineCap = PenLineCap.Round
    };

    var boundsGeo = new RectangleGeometry(new Rect(0, 0, ActualWidth, ActualHeight));

    _clipGeometry = Geometry.Combine(boundsGeo, _textGeometry, GeometryCombineMode.Exclude, null);
    drawingContext.PushClip(_clipGeometry);
    drawingContext.DrawGeometry(System.Windows.Media.Brushes.Transparent, textPen, _textGeometry);
    drawingContext.Pop();
    }
    }


    I need to change the part that get the size and position from the TextBlock in order to get the size and position of the Inline block, but I don't see any property of Inline that can get that information. Any idea?










    share|improve this question



























      0












      0








      0








      I use this example ( https://siderite.blogspot.com/2016/03/how-to-draw-outlined-text-in-wpf-and.html#at2665784896 ) for add outline to a text in a TextBlock. However this example don't support Inlines.



      I try to add this ability modifying the OnRender and I iterate the Inlines collection to build a Geometry for each Inline block. The problem is that I need to get the position and size of the inline block in the TextBlock instead of those of the whole text in the TextBlock.



      This is the source code that I have modified.



      protected override void OnRender(DrawingContext drawingContext)
      {
      ensureTextBlock();
      base.OnRender(drawingContext);

      foreach (Inline inline in _textBlock.Inlines)
      {
      var textRange = new TextRange(inline.ContentStart, inline.ContentEnd);
      var formattedText = new FormattedText(
      textRange.Text,
      CultureInfo.CurrentUICulture,
      inline.FlowDirection,
      new Typeface(inline.FontFamily, inline.FontStyle, inline.FontWeight, inline.FontStretch),
      inline.FontSize, System.Windows.Media.Brushes.Black // This brush does not matter since we use the geometry of the text.
      );
      formattedText.SetTextDecorations(inline.TextDecorations);


      //*****************************************************************
      //This part get the size and position of the TextBlock
      // Instead I need to find a way to get the size and position of the Inline block

      //formattedText.TextAlignment = _textBlock.TextAlignment;
      //formattedText.Trimming = _textBlock.TextTrimming;

      formattedText.LineHeight = _textBlock.LineHeight;
      formattedText.MaxTextWidth = _textBlock.ActualWidth - _textBlock.Padding.Left - _textBlock.Padding.Right;
      formattedText.MaxTextHeight = _textBlock.ActualHeight - _textBlock.Padding.Top;// - _textBlock.Padding.Bottom;
      while (formattedText.Extent == double.NegativeInfinity)
      {
      formattedText.MaxTextHeight++;
      }

      // Build the geometry object that represents the text.
      var _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(_textBlock.Padding.Left, _textBlock.Padding.Top));

      //*****************************************************************


      var textPen = new System.Windows.Media.Pen(Stroke, StrokeThickness * 2)
      {
      DashCap = PenLineCap.Round,
      EndLineCap = PenLineCap.Round,
      LineJoin = PenLineJoin.Round,
      StartLineCap = PenLineCap.Round
      };

      var boundsGeo = new RectangleGeometry(new Rect(0, 0, ActualWidth, ActualHeight));

      _clipGeometry = Geometry.Combine(boundsGeo, _textGeometry, GeometryCombineMode.Exclude, null);
      drawingContext.PushClip(_clipGeometry);
      drawingContext.DrawGeometry(System.Windows.Media.Brushes.Transparent, textPen, _textGeometry);
      drawingContext.Pop();
      }
      }


      I need to change the part that get the size and position from the TextBlock in order to get the size and position of the Inline block, but I don't see any property of Inline that can get that information. Any idea?










      share|improve this question
















      I use this example ( https://siderite.blogspot.com/2016/03/how-to-draw-outlined-text-in-wpf-and.html#at2665784896 ) for add outline to a text in a TextBlock. However this example don't support Inlines.



      I try to add this ability modifying the OnRender and I iterate the Inlines collection to build a Geometry for each Inline block. The problem is that I need to get the position and size of the inline block in the TextBlock instead of those of the whole text in the TextBlock.



      This is the source code that I have modified.



      protected override void OnRender(DrawingContext drawingContext)
      {
      ensureTextBlock();
      base.OnRender(drawingContext);

      foreach (Inline inline in _textBlock.Inlines)
      {
      var textRange = new TextRange(inline.ContentStart, inline.ContentEnd);
      var formattedText = new FormattedText(
      textRange.Text,
      CultureInfo.CurrentUICulture,
      inline.FlowDirection,
      new Typeface(inline.FontFamily, inline.FontStyle, inline.FontWeight, inline.FontStretch),
      inline.FontSize, System.Windows.Media.Brushes.Black // This brush does not matter since we use the geometry of the text.
      );
      formattedText.SetTextDecorations(inline.TextDecorations);


      //*****************************************************************
      //This part get the size and position of the TextBlock
      // Instead I need to find a way to get the size and position of the Inline block

      //formattedText.TextAlignment = _textBlock.TextAlignment;
      //formattedText.Trimming = _textBlock.TextTrimming;

      formattedText.LineHeight = _textBlock.LineHeight;
      formattedText.MaxTextWidth = _textBlock.ActualWidth - _textBlock.Padding.Left - _textBlock.Padding.Right;
      formattedText.MaxTextHeight = _textBlock.ActualHeight - _textBlock.Padding.Top;// - _textBlock.Padding.Bottom;
      while (formattedText.Extent == double.NegativeInfinity)
      {
      formattedText.MaxTextHeight++;
      }

      // Build the geometry object that represents the text.
      var _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(_textBlock.Padding.Left, _textBlock.Padding.Top));

      //*****************************************************************


      var textPen = new System.Windows.Media.Pen(Stroke, StrokeThickness * 2)
      {
      DashCap = PenLineCap.Round,
      EndLineCap = PenLineCap.Round,
      LineJoin = PenLineJoin.Round,
      StartLineCap = PenLineCap.Round
      };

      var boundsGeo = new RectangleGeometry(new Rect(0, 0, ActualWidth, ActualHeight));

      _clipGeometry = Geometry.Combine(boundsGeo, _textGeometry, GeometryCombineMode.Exclude, null);
      drawingContext.PushClip(_clipGeometry);
      drawingContext.DrawGeometry(System.Windows.Media.Brushes.Transparent, textPen, _textGeometry);
      drawingContext.Pop();
      }
      }


      I need to change the part that get the size and position from the TextBlock in order to get the size and position of the Inline block, but I don't see any property of Inline that can get that information. Any idea?







      c# wpf textblock inlines






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 '18 at 15:59







      user2272143

















      asked Nov 28 '18 at 15:15









      user2272143user2272143

      69110




      69110
























          2 Answers
          2






          active

          oldest

          votes


















          0














          I have found a way to get the position with:



          inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Left
          inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Top


          Then I changed the line that build the geometry in this way:



          double posLeft = inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Left;
          double posTop = inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Top;

          var _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(posLeft, posTop));


          I still have some problem with wrap because when the text is wrapped the Geometry is built only in the first line.






          share|improve this answer


























          • This needs to be an update to your question and not posted as an answer. It'll get voted down and possibly removed.

            – Michael Puckett II
            Nov 28 '18 at 21:13











          • @MichaelPuckettII This answer to my question: how get the position of Inline? inline.ElementStart.GetCharacterRect(LogicalDirection.Forward) I still have problem with wrapped text but this is beyond the goal of this question and I think I will open a new question for this point.

            – user2272143
            Nov 28 '18 at 23:46













          • Copy that; to prevent confusion I might remove the last tidbit where it says you're still having an issue. I believe I understand you correctly in that you did answer the question so the extra may leave it to leaving unanswered (which is what I originally assumed myself)

            – Michael Puckett II
            Nov 28 '18 at 23:50











          • Well, I have add that last information because if some person are looking just for my original question they get the answer but in case someone is trying to do the same thing with outlined text then he is warned that this code still have that problem. But I get your point and now I'm not sure if I have to leave it or not. Probably I'll clarify it later but since I still work on this problem I'll update my answer later if I have some better news. Anyway thanks for your suggestion.

            – user2272143
            Nov 29 '18 at 0:00





















          -1














          Use the LineHeight property of the TextBlock:



          formattedText.LineHeight = _textBlock.LineHeight;


          So you can modify the LineHeight value programmatically.






          share|improve this answer
























          • Thanks for your answer, however the problem is to get the size and position of the inline block not only the LineHeight. Each Inline block have a different size and position inside the TextBlock.

            – user2272143
            Nov 28 '18 at 15:31











          • Try separating them into different vars, may be that would make any difference.

            – sherl.lol
            Nov 28 '18 at 15:33











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53522632%2fwpf-c-sharp-get-the-size-and-position-of-inline-element-of-a-textblock%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I have found a way to get the position with:



          inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Left
          inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Top


          Then I changed the line that build the geometry in this way:



          double posLeft = inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Left;
          double posTop = inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Top;

          var _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(posLeft, posTop));


          I still have some problem with wrap because when the text is wrapped the Geometry is built only in the first line.






          share|improve this answer


























          • This needs to be an update to your question and not posted as an answer. It'll get voted down and possibly removed.

            – Michael Puckett II
            Nov 28 '18 at 21:13











          • @MichaelPuckettII This answer to my question: how get the position of Inline? inline.ElementStart.GetCharacterRect(LogicalDirection.Forward) I still have problem with wrapped text but this is beyond the goal of this question and I think I will open a new question for this point.

            – user2272143
            Nov 28 '18 at 23:46













          • Copy that; to prevent confusion I might remove the last tidbit where it says you're still having an issue. I believe I understand you correctly in that you did answer the question so the extra may leave it to leaving unanswered (which is what I originally assumed myself)

            – Michael Puckett II
            Nov 28 '18 at 23:50











          • Well, I have add that last information because if some person are looking just for my original question they get the answer but in case someone is trying to do the same thing with outlined text then he is warned that this code still have that problem. But I get your point and now I'm not sure if I have to leave it or not. Probably I'll clarify it later but since I still work on this problem I'll update my answer later if I have some better news. Anyway thanks for your suggestion.

            – user2272143
            Nov 29 '18 at 0:00


















          0














          I have found a way to get the position with:



          inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Left
          inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Top


          Then I changed the line that build the geometry in this way:



          double posLeft = inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Left;
          double posTop = inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Top;

          var _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(posLeft, posTop));


          I still have some problem with wrap because when the text is wrapped the Geometry is built only in the first line.






          share|improve this answer


























          • This needs to be an update to your question and not posted as an answer. It'll get voted down and possibly removed.

            – Michael Puckett II
            Nov 28 '18 at 21:13











          • @MichaelPuckettII This answer to my question: how get the position of Inline? inline.ElementStart.GetCharacterRect(LogicalDirection.Forward) I still have problem with wrapped text but this is beyond the goal of this question and I think I will open a new question for this point.

            – user2272143
            Nov 28 '18 at 23:46













          • Copy that; to prevent confusion I might remove the last tidbit where it says you're still having an issue. I believe I understand you correctly in that you did answer the question so the extra may leave it to leaving unanswered (which is what I originally assumed myself)

            – Michael Puckett II
            Nov 28 '18 at 23:50











          • Well, I have add that last information because if some person are looking just for my original question they get the answer but in case someone is trying to do the same thing with outlined text then he is warned that this code still have that problem. But I get your point and now I'm not sure if I have to leave it or not. Probably I'll clarify it later but since I still work on this problem I'll update my answer later if I have some better news. Anyway thanks for your suggestion.

            – user2272143
            Nov 29 '18 at 0:00
















          0












          0








          0







          I have found a way to get the position with:



          inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Left
          inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Top


          Then I changed the line that build the geometry in this way:



          double posLeft = inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Left;
          double posTop = inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Top;

          var _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(posLeft, posTop));


          I still have some problem with wrap because when the text is wrapped the Geometry is built only in the first line.






          share|improve this answer















          I have found a way to get the position with:



          inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Left
          inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Top


          Then I changed the line that build the geometry in this way:



          double posLeft = inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Left;
          double posTop = inline.ElementStart.GetCharacterRect(LogicalDirection.Forward).Top;

          var _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(posLeft, posTop));


          I still have some problem with wrap because when the text is wrapped the Geometry is built only in the first line.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 28 '18 at 18:10

























          answered Nov 28 '18 at 17:54









          user2272143user2272143

          69110




          69110













          • This needs to be an update to your question and not posted as an answer. It'll get voted down and possibly removed.

            – Michael Puckett II
            Nov 28 '18 at 21:13











          • @MichaelPuckettII This answer to my question: how get the position of Inline? inline.ElementStart.GetCharacterRect(LogicalDirection.Forward) I still have problem with wrapped text but this is beyond the goal of this question and I think I will open a new question for this point.

            – user2272143
            Nov 28 '18 at 23:46













          • Copy that; to prevent confusion I might remove the last tidbit where it says you're still having an issue. I believe I understand you correctly in that you did answer the question so the extra may leave it to leaving unanswered (which is what I originally assumed myself)

            – Michael Puckett II
            Nov 28 '18 at 23:50











          • Well, I have add that last information because if some person are looking just for my original question they get the answer but in case someone is trying to do the same thing with outlined text then he is warned that this code still have that problem. But I get your point and now I'm not sure if I have to leave it or not. Probably I'll clarify it later but since I still work on this problem I'll update my answer later if I have some better news. Anyway thanks for your suggestion.

            – user2272143
            Nov 29 '18 at 0:00





















          • This needs to be an update to your question and not posted as an answer. It'll get voted down and possibly removed.

            – Michael Puckett II
            Nov 28 '18 at 21:13











          • @MichaelPuckettII This answer to my question: how get the position of Inline? inline.ElementStart.GetCharacterRect(LogicalDirection.Forward) I still have problem with wrapped text but this is beyond the goal of this question and I think I will open a new question for this point.

            – user2272143
            Nov 28 '18 at 23:46













          • Copy that; to prevent confusion I might remove the last tidbit where it says you're still having an issue. I believe I understand you correctly in that you did answer the question so the extra may leave it to leaving unanswered (which is what I originally assumed myself)

            – Michael Puckett II
            Nov 28 '18 at 23:50











          • Well, I have add that last information because if some person are looking just for my original question they get the answer but in case someone is trying to do the same thing with outlined text then he is warned that this code still have that problem. But I get your point and now I'm not sure if I have to leave it or not. Probably I'll clarify it later but since I still work on this problem I'll update my answer later if I have some better news. Anyway thanks for your suggestion.

            – user2272143
            Nov 29 '18 at 0:00



















          This needs to be an update to your question and not posted as an answer. It'll get voted down and possibly removed.

          – Michael Puckett II
          Nov 28 '18 at 21:13





          This needs to be an update to your question and not posted as an answer. It'll get voted down and possibly removed.

          – Michael Puckett II
          Nov 28 '18 at 21:13













          @MichaelPuckettII This answer to my question: how get the position of Inline? inline.ElementStart.GetCharacterRect(LogicalDirection.Forward) I still have problem with wrapped text but this is beyond the goal of this question and I think I will open a new question for this point.

          – user2272143
          Nov 28 '18 at 23:46







          @MichaelPuckettII This answer to my question: how get the position of Inline? inline.ElementStart.GetCharacterRect(LogicalDirection.Forward) I still have problem with wrapped text but this is beyond the goal of this question and I think I will open a new question for this point.

          – user2272143
          Nov 28 '18 at 23:46















          Copy that; to prevent confusion I might remove the last tidbit where it says you're still having an issue. I believe I understand you correctly in that you did answer the question so the extra may leave it to leaving unanswered (which is what I originally assumed myself)

          – Michael Puckett II
          Nov 28 '18 at 23:50





          Copy that; to prevent confusion I might remove the last tidbit where it says you're still having an issue. I believe I understand you correctly in that you did answer the question so the extra may leave it to leaving unanswered (which is what I originally assumed myself)

          – Michael Puckett II
          Nov 28 '18 at 23:50













          Well, I have add that last information because if some person are looking just for my original question they get the answer but in case someone is trying to do the same thing with outlined text then he is warned that this code still have that problem. But I get your point and now I'm not sure if I have to leave it or not. Probably I'll clarify it later but since I still work on this problem I'll update my answer later if I have some better news. Anyway thanks for your suggestion.

          – user2272143
          Nov 29 '18 at 0:00







          Well, I have add that last information because if some person are looking just for my original question they get the answer but in case someone is trying to do the same thing with outlined text then he is warned that this code still have that problem. But I get your point and now I'm not sure if I have to leave it or not. Probably I'll clarify it later but since I still work on this problem I'll update my answer later if I have some better news. Anyway thanks for your suggestion.

          – user2272143
          Nov 29 '18 at 0:00















          -1














          Use the LineHeight property of the TextBlock:



          formattedText.LineHeight = _textBlock.LineHeight;


          So you can modify the LineHeight value programmatically.






          share|improve this answer
























          • Thanks for your answer, however the problem is to get the size and position of the inline block not only the LineHeight. Each Inline block have a different size and position inside the TextBlock.

            – user2272143
            Nov 28 '18 at 15:31











          • Try separating them into different vars, may be that would make any difference.

            – sherl.lol
            Nov 28 '18 at 15:33
















          -1














          Use the LineHeight property of the TextBlock:



          formattedText.LineHeight = _textBlock.LineHeight;


          So you can modify the LineHeight value programmatically.






          share|improve this answer
























          • Thanks for your answer, however the problem is to get the size and position of the inline block not only the LineHeight. Each Inline block have a different size and position inside the TextBlock.

            – user2272143
            Nov 28 '18 at 15:31











          • Try separating them into different vars, may be that would make any difference.

            – sherl.lol
            Nov 28 '18 at 15:33














          -1












          -1








          -1







          Use the LineHeight property of the TextBlock:



          formattedText.LineHeight = _textBlock.LineHeight;


          So you can modify the LineHeight value programmatically.






          share|improve this answer













          Use the LineHeight property of the TextBlock:



          formattedText.LineHeight = _textBlock.LineHeight;


          So you can modify the LineHeight value programmatically.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 28 '18 at 15:23









          sherl.lolsherl.lol

          11




          11













          • Thanks for your answer, however the problem is to get the size and position of the inline block not only the LineHeight. Each Inline block have a different size and position inside the TextBlock.

            – user2272143
            Nov 28 '18 at 15:31











          • Try separating them into different vars, may be that would make any difference.

            – sherl.lol
            Nov 28 '18 at 15:33



















          • Thanks for your answer, however the problem is to get the size and position of the inline block not only the LineHeight. Each Inline block have a different size and position inside the TextBlock.

            – user2272143
            Nov 28 '18 at 15:31











          • Try separating them into different vars, may be that would make any difference.

            – sherl.lol
            Nov 28 '18 at 15:33

















          Thanks for your answer, however the problem is to get the size and position of the inline block not only the LineHeight. Each Inline block have a different size and position inside the TextBlock.

          – user2272143
          Nov 28 '18 at 15:31





          Thanks for your answer, however the problem is to get the size and position of the inline block not only the LineHeight. Each Inline block have a different size and position inside the TextBlock.

          – user2272143
          Nov 28 '18 at 15:31













          Try separating them into different vars, may be that would make any difference.

          – sherl.lol
          Nov 28 '18 at 15:33





          Try separating them into different vars, may be that would make any difference.

          – sherl.lol
          Nov 28 '18 at 15:33


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53522632%2fwpf-c-sharp-get-the-size-and-position-of-inline-element-of-a-textblock%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)