开发者

WPF: Anyone else using textboxes instead of labels?

开发者 https://www.devze.com 2023-02-11 02:00 出处:网络
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:

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 TextBlocks instead of Labels.

  • TextBox = editable text field
  • Label = uneditable text usually tied to a form field
  • TextBlock = 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/

0

精彩评论

暂无评论...
验证码 换一张
取 消