Click here to Skip to main content
15,891,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I'm having difficulties with WPF label control. I've made the label read text from sql database but sometimes the text becomes longer and the label can't show it all and part of the text goes hidden. I need to make the label height more larger when the text is more. Is there any way to do that? Thanks in advance for any help!
Posted
Updated 21-Sep-21 20:44pm
Comments
Wayne Gaylard 7-Jul-11 4:27am    
Can you post the xaml you are using.
Sergey Alexandrovich Kryukov 7-Jul-11 4:35am    
It might not help much. What would help is a general idea of the layout and functionality, on a simple example. I provided some general answer, please see.
--SA

Don't use absolute positioning and sizes at all. Make all controls docked, feeling their containers, placed in the relatively-sized grids. Utilize Window.SizeToContent, StackPanel, WrapPanel, DockPanel in your UI design. Use Margin and Padding properties, share them using Window.Resources with ResourceDictionary.

Using these techniques properly will make the application tolerant to size of strings, size of Windows (in the limits defined by correctly set Window.MinWidth and Window.MinHeight) and screen resolution.

Using these techniques properly needs certain experience which is hard to conduct is a single CodeProject solution. I hope the idea is more or less clear.

—SA
 
Share this answer
 
Comments
George Findulov 7-Jul-11 7:06am    
Thank you for your answer! I'll try to accomplish my desired result using these controls you wrote.
Sergey Alexandrovich Kryukov 7-Jul-11 13:35pm    
You're welcome.
Will you formally accept this answer (green button)?
If you have some questions, feel free to ask. You can notify me about your new question by replying to this comment.

One more good idea is practice manually typing in XAML window, where intellisence helps you better and no numerical data is entered. What you add to XAML gets default layout with minimal set of properties which you can adjust later. It helps to sort out key properties from additional ones.

--SA
Espen Harlinn 7-Jul-11 13:09pm    
Good points, my 5
Sergey Alexandrovich Kryukov 7-Jul-11 13:35pm    
Thank you, Espen.
--SA
Please check this:

XML
<Label >
           <AccessText TextWrapping ="Wrap">
               _Lorem ipsum dolor sit amet, consectetur adipiscing elit.
               _Lorem ipsum dolor sit amet, consectetur adipiscing elit._Lorem ipsum dolor sit amet, consectetur adipiscing elit._Lorem ipsum dolor sit amet, consectetur adipiscing elit._Lorem ipsum dolor sit amet, consectetur adipiscing elit._Lorem ipsum dolor sit amet, consectetur adipiscing elit._Lorem ipsum dolor sit amet, consectetur adipiscing elit._Lorem ipsum dolor sit amet, consectetur adipiscing elit._Lorem ipsum dolor sit amet, consectetur adipiscing elit.
           </ AccessText >
       </ Label >
 
Share this answer
 
Comments
George Findulov 7-Jul-11 7:09am    
Thanks, it actually works for me in design mode but as I've written i load the information from SQL db. So how to set the text in this way using C#?
[no name] 7-Jul-11 12:27pm    
i think you dont want to use your brain.

<Label>
<AccessText Name="txt" TextWrapping="Wrap">

</AccessText>
</Label>


in code behind

txt.Text = "_Lorem ipsum dolor sit amet, consectetur adipiscing elit._Lorem ipsum dolor sit amet, consectetur adipiscing elit._Lorem ipsum dolor sit amet, consectetur adipiscing elit._Lorem ipsum dolor sit amet, consectetur adipiscing elit._Lorem ipsum dolor sit amet, consectetur adipiscing elit._Lorem ipsum dolor sit amet, consectetur adipiscing elit._Lorem ipsum dolor sit amet, consectetur adipiscing elit._Lorem ipsum dolor sit amet, consectetur adipiscing elit._Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

Please read your basics. MSDN is your best friend.
George Findulov 10-Jul-11 6:43am    
Yeah, i figured it out a little bit later after i posted. Thanks for the information anyway!
If you can use a TextBlock instead of label there is the property called TextWrapping witch does exactly this.
 
Share this answer
 
v3
Comments
Richard Deeming 22-Sep-21 4:23am    
Solution 2, posted over 10 years ago, already demonstrated using the TextWrapping property.
Member 13938280 22-Sep-21 4:32am    
Sorry, yes you are right. I haven't seen it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900