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. TextBox trigger question

TextBox trigger question

Scheduled Pinned Locked Moved WPF
wpfcsharpdatabasehelptutorial
2 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.
  • Q Offline
    Q Offline
    QzRz
    wrote on last edited by
    #1

    Hello I have a textBox which I want to add some "ghost" text on, which is visible whenever the textbox does not have focus. I could do it with codebehind, but since I am new to WPF and XAML I would like to do it all from XAML code, to get some practice. Currently my XAML code looks like this:

    <TextBox x:Name="textBoxUsername" Margin="5,5">
    <TextBox.Style>
    <Style TargetType="TextBox">
    <Style.Triggers>
    <Trigger Property="IsFocused" Value="false">
    <Setter Property="Text" Value="Username"/>
    <Setter Property="Foreground" Value="LightGray"/>
    <Setter Property="FontStyle" Value="Italic"/>
    </Trigger>
    </Style.Triggers>
    </Style>
    </TextBox.Style>
    </TextBox>

    What I would like to do, is add another statement to the trigger so it checks if the text is set by the user. This is where I need help, I cannot figure out what to write, so it checks if the text is set by the user or not. If this is not the right way to solve this, I would be happy to get an Article/blog/something which describes how to do it :) //QzRz

    D 1 Reply Last reply
    0
    • Q QzRz

      Hello I have a textBox which I want to add some "ghost" text on, which is visible whenever the textbox does not have focus. I could do it with codebehind, but since I am new to WPF and XAML I would like to do it all from XAML code, to get some practice. Currently my XAML code looks like this:

      <TextBox x:Name="textBoxUsername" Margin="5,5">
      <TextBox.Style>
      <Style TargetType="TextBox">
      <Style.Triggers>
      <Trigger Property="IsFocused" Value="false">
      <Setter Property="Text" Value="Username"/>
      <Setter Property="Foreground" Value="LightGray"/>
      <Setter Property="FontStyle" Value="Italic"/>
      </Trigger>
      </Style.Triggers>
      </Style>
      </TextBox.Style>
      </TextBox>

      What I would like to do, is add another statement to the trigger so it checks if the text is set by the user. This is where I need help, I cannot figure out what to write, so it checks if the text is set by the user or not. If this is not the right way to solve this, I would be happy to get an Article/blog/something which describes how to do it :) //QzRz

      D Offline
      D Offline
      Daniel Vaughan
      wrote on last edited by
      #2

      Hi, Here is a blog post I found that might be of use to you: http://swt1962.spaces.live.com/blog/cns!3C6545A442A42401!291.entry[^] Cheers, Daniel

      Daniel Vaughan Blog: DanielVaughan.Orpius.com
      Company: Outcoder

      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