Reputation: 4443
I cannot get proper desired size of my TextBlock.
I have few lines of code:
TextBlock block = new TextBlock();
block.Style = this.TextStyle;
block.UpdateLayout();
block.Measure(new Size(this.ActualWidth, this.ActualHeight));
block.Text = "3333";
return block.DesiredSize;
And i cannot solve two problems with it:
block.DesiredSize.Width is always zero. When height calculated properly.
Desired Size not changes when i set setters for style "TextStyle" For example setter set for FontSize with value 50.
<Setter Property="FontSize"
Value="50">
</Setter>
But Desired height only 15! What wrong with this measure method? And how can i get real size of text block?
Upvotes: 1
Views: 1268
Reputation:
Try this
TextBlock block = new TextBlock();
block.Text = "3333";
block.Style = this.TextStyle;
block.Measure(new Size(this.ActualWidth, this.ActualHeight));
block.UpdateLayout();
return block.DesiredSize;
Upvotes: 2