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. button style

button style

Scheduled Pinned Locked Moved WPF
questiondatabase
5 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.
  • M Offline
    M Offline
    michaelgr1
    wrote on last edited by
    #1

    Hello,

    I have a button which has 2 labels. I want the labels foreground to be black on mouse over button and white when mouse is not over button.

    I used this :

    <Style TargetType="{x:Type Label}" >
    <Style.Triggers>
    <Trigger Property="IsMouseOver" Value="true">
    <Setter Property="Foreground" Value="Black"/>
    </Trigger>
    <Trigger Property="IsMouseOver" Value="false">
    <Setter Property="Foreground" Value="White"/>
    </Trigger>
    </Style.Triggers>
    </Style>
    But the thing is that label foreground is changed only when i am over the label. so one label is black and second is white.

    How can i solve this so when mouse is over the button, it's children labels will use this style?

    P B 2 Replies Last reply
    0
    • M michaelgr1

      Hello,

      I have a button which has 2 labels. I want the labels foreground to be black on mouse over button and white when mouse is not over button.

      I used this :

      <Style TargetType="{x:Type Label}" >
      <Style.Triggers>
      <Trigger Property="IsMouseOver" Value="true">
      <Setter Property="Foreground" Value="Black"/>
      </Trigger>
      <Trigger Property="IsMouseOver" Value="false">
      <Setter Property="Foreground" Value="White"/>
      </Trigger>
      </Style.Triggers>
      </Style>
      But the thing is that label foreground is changed only when i am over the label. so one label is black and second is white.

      How can i solve this so when mouse is over the button, it's children labels will use this style?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You only need to supply one trigger. What you do is define the standard style, and as you have a boolean condition, the other condition will be applied when appropriate. Here's what I mean:

      <Style TargetType="{x:Type Label}">
      <Setter Property="Foreground" Value="Black" />
      <Style.Triggers>
      <Trigger Property="IsMouseOver" Value="False">
      <Setter Property="Foreground" Value="White" />
      </Trigger>
      </Style.Triggers>
      </Style>

      As you can see, you have a default style which gets overriden by the trigger, and when the trigger no longer applies, it reverts back to the default style.

      *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

      M 1 Reply Last reply
      0
      • P Pete OHanlon

        You only need to supply one trigger. What you do is define the standard style, and as you have a boolean condition, the other condition will be applied when appropriate. Here's what I mean:

        <Style TargetType="{x:Type Label}">
        <Setter Property="Foreground" Value="Black" />
        <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="False">
        <Setter Property="Foreground" Value="White" />
        </Trigger>
        </Style.Triggers>
        </Style>

        As you can see, you have a default style which gets overriden by the trigger, and when the trigger no longer applies, it reverts back to the default style.

        *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

        "Mind bleach! Send me mind bleach!" - Nagy Vilmos

        My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

        M Offline
        M Offline
        michaelgr1
        wrote on last edited by
        #3

        Right but that's not what i meant. I meant that i have a button with 2 labels. But only one of them becomes black when mouse is over one of them , and second label stays white. i want a functionality that when mouse is over the button, both labels will be black.

        P 1 Reply Last reply
        0
        • M michaelgr1

          Hello,

          I have a button which has 2 labels. I want the labels foreground to be black on mouse over button and white when mouse is not over button.

          I used this :

          <Style TargetType="{x:Type Label}" >
          <Style.Triggers>
          <Trigger Property="IsMouseOver" Value="true">
          <Setter Property="Foreground" Value="Black"/>
          </Trigger>
          <Trigger Property="IsMouseOver" Value="false">
          <Setter Property="Foreground" Value="White"/>
          </Trigger>
          </Style.Triggers>
          </Style>
          But the thing is that label foreground is changed only when i am over the label. so one label is black and second is white.

          How can i solve this so when mouse is over the button, it's children labels will use this style?

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          Your trigger is applied to a label, not to the button. Because "IsMouseOver" is a property of an individual label, the other label on the button is not influenced. Could you also provide the code of your button?

          1 Reply Last reply
          0
          • M michaelgr1

            Right but that's not what i meant. I meant that i have a button with 2 labels. But only one of them becomes black when mouse is over one of them , and second label stays white. i want a functionality that when mouse is over the button, both labels will be black.

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            Ahh, I see. Well, you need to give the label you are interested in a name, and use TargetName in your style trigger setter to change the style. The actual style you have as the main style should be Button not Label.

            *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

            My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

            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