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. Styles in WPF

Styles in WPF

Scheduled Pinned Locked Moved WPF
wpfhelpcsharptutorialquestion
6 Posts 2 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.
  • Y Offline
    Y Offline
    Yoyosch
    wrote on last edited by
    #1

    Hi, I have a simple code snippet that changes the color of a background of a boder using animation. How to define that in style? I am getting the error message saying that I cannot specificy TargetName. <Border.Background> <SolidColorBrush x:Name="brush"></SolidColorBrush> </Border.Background> <Border.Triggers> <EventTrigger RoutedEvent="Border.MouseEnter"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetName="brush" Storyboard.TargetProperty="Color" To="Yellow" Duration="0:0:0.5"></ColorAnimation> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <EventTrigger RoutedEvent="Border.MouseLeave"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetName="brush" Storyboard.TargetProperty="Color" To="Transparent" Duration="0:0:0.5"></ColorAnimation> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> </Border.Triggers> Thanks in advance for help

    _ 1 Reply Last reply
    0
    • Y Yoyosch

      Hi, I have a simple code snippet that changes the color of a background of a boder using animation. How to define that in style? I am getting the error message saying that I cannot specificy TargetName. <Border.Background> <SolidColorBrush x:Name="brush"></SolidColorBrush> </Border.Background> <Border.Triggers> <EventTrigger RoutedEvent="Border.MouseEnter"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetName="brush" Storyboard.TargetProperty="Color" To="Yellow" Duration="0:0:0.5"></ColorAnimation> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <EventTrigger RoutedEvent="Border.MouseLeave"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetName="brush" Storyboard.TargetProperty="Color" To="Transparent" Duration="0:0:0.5"></ColorAnimation> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> </Border.Triggers> Thanks in advance for help

      _ Offline
      _ Offline
      _iobuf
      wrote on last edited by
      #2

      Style looks like this: <setter property="Template"> <setter.value> <controltemplate targettype="{x:Type Button}"> <controltemplate.resources> <!-- Storyboards go here --> </controltemplate.resources> <grid> <!-- Content goes here --> </grid> <controltemplate.triggers> <!-- Triggers go here --> </controltemplate.triggers> </controltemplate> </setter.value> </setter> You have to put everything in the appropriate place for it to work, then apply the style to the element you want

      Y 1 Reply Last reply
      0
      • _ _iobuf

        Style looks like this: <setter property="Template"> <setter.value> <controltemplate targettype="{x:Type Button}"> <controltemplate.resources> <!-- Storyboards go here --> </controltemplate.resources> <grid> <!-- Content goes here --> </grid> <controltemplate.triggers> <!-- Triggers go here --> </controltemplate.triggers> </controltemplate> </setter.value> </setter> You have to put everything in the appropriate place for it to work, then apply the style to the element you want

        Y Offline
        Y Offline
        Yoyosch
        wrote on last edited by
        #3

        Thanks for reply! Is it possible to do that without defining a template? I believe that a simple style with 2 triggers would be enough

        _ 1 Reply Last reply
        0
        • Y Yoyosch

          Thanks for reply! Is it possible to do that without defining a template? I believe that a simple style with 2 triggers would be enough

          _ Offline
          _ Offline
          _iobuf
          wrote on last edited by
          #4

          Yes. I think you can just ignore the "template" setter.. so just erase the

          Y 1 Reply Last reply
          0
          • _ _iobuf

            Yes. I think you can just ignore the "template" setter.. so just erase the

            Y Offline
            Y Offline
            Yoyosch
            wrote on last edited by
            #5

            I thought the same and tried it, but it didn`t work. I got an error like I wrote in first post.

            _ 1 Reply Last reply
            0
            • Y Yoyosch

              I thought the same and tried it, but it didn`t work. I got an error like I wrote in first post.

              _ Offline
              _ Offline
              _iobuf
              wrote on last edited by
              #6

              You can do

              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