C
C#6mo ago
Karthik

WPF app, having trouble setting vertical bounds on a TextBlock

I am building a WPF application that can project song lyrics on second screen stanza by stanza I am facing a challenge to set the font size on the MonitorPreviewPanel which is TextBlock basically I implemented a slider that can set font size and the when the textsize is increased and when the width of the text hits the left and right ends the text is getting wrapped But somehow the vertical bonds are not working, the text is overflowing when the text hits the top and bottom
13 Replies
canton7
canton76mo ago
Can you post some images, so we can visualise what you're saying?
Karthik
KarthikOP6mo ago
This is how it looks by default - which is expected behavior
No description
Karthik
KarthikOP6mo ago
This is how it's appearing when I increase font size(overflow on Y axis)
No description
Karthik
KarthikOP6mo ago
what I am expecting is this- the user should be able to increase font only until the text touches the top and bottom edges
canton7
canton76mo ago
That's not how it works, though. Font size has priority You might be able to use a ViewBox, either instead of scaling up, or to scale it down once the font size gets too large
Hannsen
Hannsen6mo ago
If you want to achieve, that the TextBox is shown with the largest view possible, then try to wrap it in a ViewBox control. - FontSize then does not matter anymore directly. With this, you could also get rid of the Slider control at all. Like: <Viewbox> <TextBox /> <Viewbox> Would that be a solution for you? - Otherwise, you are in need to kind of also control the Padding of the TextBox dynamically depending on a ratio, which i would not recommend,
Karthik
KarthikOP6mo ago
yes I tried with viewbox, it is helping with my requirement but there is a dowside instead of setting fontsize according the available space it is squuezing in the text, because of which the text looks bad here is a screenshot, I repeated the first line jst for demo
No description
Karthik
KarthikOP6mo ago
I used Stretch="Fill"
Karthik
KarthikOP6mo ago
this is how it should actully look like I set font size manually here
No description
canton7
canton75mo ago
That's your problem. Stretch doesn't preserve the aspect ratio. Try Fill, see https://learn.microsoft.com/en-us/dotnet/api/system.windows.media.stretch
Karthik
KarthikOP5mo ago
I set the mode as 'Fill' Sorry, didn't get you. Stretch is the property name correct? And Fill/Uniform are the modes
canton7
canton75mo ago
Oh sorry, it's first thing in the morning here >< Fill doesn't preserve the aspect ratio. Try Uniform
Karthik
KarthikOP5mo ago
This is how it looks when I use Uniform Using uniform is not showing largest possible text. If the width is longer then it is not utilising the space on top and bottom @canton7
Want results from more Discord servers?
Add your server