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. WPF TextBlock Trigger Question

WPF TextBlock Trigger Question

Scheduled Pinned Locked Moved WPF
wpfquestioncsharpdatabasewcf
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.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    I am trying to hide a text block. When a Checkbox is checked, it should be hidden. When it's unchecked the textblock should be visible. The checkbox is bound to an object called SelectedProcess. If SelectedProcess is null, the textblock should be hidden. Here's my XAML:

            <Style.Triggers>
                <DataTrigger Binding="{Binding SelectedProcess}" Value="Null">
                    <Setter Property="UIElement.Visibility" Value="Hidden"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding SelectedProcess.Enabled}" Value="True">
                    <Setter Property="UIElement.Visibility" Value="Hidden"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding SelectedProcess.Enabled}" Value="False">
                    <Setter Property="UIElement.Visibility" Value="Visible"/>
                </DataTrigger>
            </Style.Triggers>
    

    It works when SelectedProcess is NOT null, but when SelectedProcess IS null, the text is still visible. What am I doing wrong here? Thanks

    If it's not broken, fix it until it is

    Richard DeemingR 1 Reply Last reply
    0
    • K Kevin Marois

      I am trying to hide a text block. When a Checkbox is checked, it should be hidden. When it's unchecked the textblock should be visible. The checkbox is bound to an object called SelectedProcess. If SelectedProcess is null, the textblock should be hidden. Here's my XAML:

              <Style.Triggers>
                  <DataTrigger Binding="{Binding SelectedProcess}" Value="Null">
                      <Setter Property="UIElement.Visibility" Value="Hidden"/>
                  </DataTrigger>
                  <DataTrigger Binding="{Binding SelectedProcess.Enabled}" Value="True">
                      <Setter Property="UIElement.Visibility" Value="Hidden"/>
                  </DataTrigger>
                  <DataTrigger Binding="{Binding SelectedProcess.Enabled}" Value="False">
                      <Setter Property="UIElement.Visibility" Value="Visible"/>
                  </DataTrigger>
              </Style.Triggers>
      

      It works when SelectedProcess is NOT null, but when SelectedProcess IS null, the text is still visible. What am I doing wrong here? Thanks

      If it's not broken, fix it until it is

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Try Value="{x:Null}" instead. http://msdn.microsoft.com/en-us/library/ms743649%28v=vs.110%29.aspx[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      K 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        Try Value="{x:Null}" instead. http://msdn.microsoft.com/en-us/library/ms743649%28v=vs.110%29.aspx[^]


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        K Offline
        K Offline
        Kevin Marois
        wrote on last edited by
        #3

        That did it. Thank you!

        If it's not broken, fix it until it is

        B 1 Reply Last reply
        0
        • K Kevin Marois

          That did it. Thank you!

          If it's not broken, fix it until it is

          B Offline
          B Offline
          BubingaMan
          wrote on last edited by
          #4

          Your issue seems fixed, which is great. However, I wonder why you use datatriggers to accomplish this. Consider doing it through binding instead with the help of a converter. If the visibility of the texblock is always directly related to the checkbox being checked / unchecked, then you could use elementbinding to do so.

          The resulting XAML is simpler and achieves the same result.

          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