I'm just curious.. In my application I'm using "readonly and borderless" textboxes instead of using labels. The textboxes are based on this Style I keep in my resource file:
<Style TargetType="{x:Type TextBox}" x:Key="LabelLeftStyle" BasedOn="{StaticResource Basic}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="I开发者_如何学CsReadOnly" Value="True"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Height" Value="Auto" />
<Setter Property="Width" Value="Auto" />
<Setter Property="MinWidth" Value="155"/>
<Setter Property="IsTabStop" Value="False"/>
</Style>
Just curious..is anyone else doing the same ? I found the WPF Label difficult to work with.
Use TextBlock
s instead of Label
s.
TextBox
= editable text fieldLabel
= uneditable text usually tied to a form fieldTextBlock
= generic uneditable text
I can tell you this much, we use TextBlock
and Label
extensively for static text display in multiple WPF applications without issue. How was the Label
difficult to use? Perhaps if you list some specific problems we could provide some guidance.
This is really strange that you have chosen to use text boxes (styled in special way) over labels. Because text boxes are designed for a different purpose... Usually the choice is whether to use TextBlock
or Label
.
You haven't mentioned why exactly labels are hard to use... If it is because of extra margins that label has by default, then it is easy to fix with a style for all labels in you application.
Anyway, there is a good article about the difference between TextBlock
and Label
that describes what are the reasons why such a control as Label
exist: http://joshsmithonwpf.wordpress.com/2007/07/04/differences-between-label-and-textblock/
精彩评论