Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. The difference of Style on Button and TextBlock,

The difference of Style on Button and TextBlock,

Scheduled Pinned Locked Moved WPF
csharpwpf
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    econy
    wrote on last edited by
    #1

    <Setter Property="HorizontalAlignment" Value="Center" />
    <Setter Property="FontFamily" Value="Comic Sans MS"/>
    <Setter Property="FontSize" Value="20"/>

        <Setter Property="Height" Value="36"/>
            <Setter Property="Width" Value="60"/>
        
    
    <Button Content="Button" Style="{StaticResource ButtonStyle}"/>
        <Button Content="Button" Style="{StaticResource ButtonStyle}" Margin="156,144,286,145" />
    

    I am a rookie in WPF, I am wonder why the Button need : Style="{StaticResource ButtonStyle}" , a explicit Style syntax. But the TextBlock don't need it. Thanks

    M L 2 Replies Last reply
    0
    • E econy

      <Setter Property="HorizontalAlignment" Value="Center" />
      <Setter Property="FontFamily" Value="Comic Sans MS"/>
      <Setter Property="FontSize" Value="20"/>

          <Setter Property="Height" Value="36"/>
              <Setter Property="Width" Value="60"/>
          
      
      <Button Content="Button" Style="{StaticResource ButtonStyle}"/>
          <Button Content="Button" Style="{StaticResource ButtonStyle}" Margin="156,144,286,145" />
      

      I am a rookie in WPF, I am wonder why the Button need : Style="{StaticResource ButtonStyle}" , a explicit Style syntax. But the TextBlock don't need it. Thanks

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      I assume you did not write the code for this! Somewhere the author has defined a style called ButtonStyle , probably in a resources folder. It will be defined in your App.xaml file as a resources dictionary, or possibly in your window/page .xaml file. The author has decided to customise the standard layout of the Button but not the TextBox.

      Never underestimate the power of human stupidity RAH

      E 1 Reply Last reply
      0
      • M Mycroft Holmes

        I assume you did not write the code for this! Somewhere the author has defined a style called ButtonStyle , probably in a resources folder. It will be defined in your App.xaml file as a resources dictionary, or possibly in your window/page .xaml file. The author has decided to customise the standard layout of the Button but not the TextBox.

        Never underestimate the power of human stupidity RAH

        E Offline
        E Offline
        econy
        wrote on last edited by
        #3

        Thanks, Yes, I wrote code like that,I wonder why the Setter for Button not works for all Buttons without . But, the Setter for TextBlock works for all TextBlocks, don't need to type <Style StaticResource ...></x-turndown>

        1 Reply Last reply
        0
        • E econy

          <Setter Property="HorizontalAlignment" Value="Center" />
          <Setter Property="FontFamily" Value="Comic Sans MS"/>
          <Setter Property="FontSize" Value="20"/>

              <Setter Property="Height" Value="36"/>
                  <Setter Property="Width" Value="60"/>
              
          
          <Button Content="Button" Style="{StaticResource ButtonStyle}"/>
              <Button Content="Button" Style="{StaticResource ButtonStyle}" Margin="156,144,286,145" />
          

          I am a rookie in WPF, I am wonder why the Button need : Style="{StaticResource ButtonStyle}" , a explicit Style syntax. But the TextBlock don't need it. Thanks

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          In the "Resources" section, you assigned a "Key" ("ButtonStyle" in this case ... it could have been called "Foo") to the Button style; the TextBlock style doesn't have a Key. Any style with a "Key" needs to be referenced via that Key (e.g. StaticResource ButtonStyle) in order to be applied to the relevant control. The TextBlock style (in this case) is applied to any TextBlock that is in the "scope" of that style (without needing a Key).

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups