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. DataTrigger not working

DataTrigger not working

Scheduled Pinned Locked Moved WPF
csswpfwcfquestion
4 Posts 3 Posters 5 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'm trying to implement show/hide password textboxes. There is a PasswordBox and a TextBox both in the same grid cell, and a checkbox off to the right. When I check it, nothing happens. I get no binding errors. Anyone see what's wrong?

            <Style.Triggers>
                                <DataTrigger Binding="{Binding ElementName=chkShowPassword, Path=IsChecked}" Value="False">
                                    <Setter Property="Visibility" Value="Hidden"/>
                                </DataTrigger>
                            </Style.Triggers>
                        
                    
                    
                
    
                <Style.Triggers>
                                <DataTrigger Binding="{Binding ElementName=chkShowPassword, Path=IsCheckd}"  Value="True">
                                    <Setter Property="Visibility" Value="Visible"/>
                                </DataTrigger>
                            </Style.Triggers>
    
    D Richard DeemingR 2 Replies Last reply
    0
    • K Kevin Marois

      I'm trying to implement show/hide password textboxes. There is a PasswordBox and a TextBox both in the same grid cell, and a checkbox off to the right. When I check it, nothing happens. I get no binding errors. Anyone see what's wrong?

              <Style.Triggers>
                                  <DataTrigger Binding="{Binding ElementName=chkShowPassword, Path=IsChecked}" Value="False">
                                      <Setter Property="Visibility" Value="Hidden"/>
                                  </DataTrigger>
                              </Style.Triggers>
                          
                      
                      
                  
      
                  <Style.Triggers>
                                  <DataTrigger Binding="{Binding ElementName=chkShowPassword, Path=IsCheckd}"  Value="True">
                                      <Setter Property="Visibility" Value="Visible"/>
                                  </DataTrigger>
                              </Style.Triggers>
      
      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You don't have anything that submits the username and password. There is no "login" button. But, figuring out if the credentials are correct is not done in the XAML. It's done in the class your XAML is bound to, which you also didn't show. Sorry, I completely misread the question.

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      1 Reply Last reply
      0
      • K Kevin Marois

        I'm trying to implement show/hide password textboxes. There is a PasswordBox and a TextBox both in the same grid cell, and a checkbox off to the right. When I check it, nothing happens. I get no binding errors. Anyone see what's wrong?

                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=chkShowPassword, Path=IsChecked}" Value="False">
                                        <Setter Property="Visibility" Value="Hidden"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            
                        
                        
                    
        
                    <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=chkShowPassword, Path=IsCheckd}"  Value="True">
                                        <Setter Property="Visibility" Value="Visible"/>
                                    </DataTrigger>
                                </Style.Triggers>
        
        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        The Visibility property set directly on the control overrides the value set by the style. You also have the trigger on the password box the wrong way round - you want to hide it when the checkbox is checked, not unchecked. And you have a typo in the binding for the textbox - IsCheckd instead of IsChecked. Change your code to:

        <PasswordBox
        Grid.Row="0"
        Grid.Column="0"
        TabIndex="2"
        cls:PasswordBoxAssistant.BindPassword="True"
        cls:PasswordBoxAssistant.BoundPassword="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        Width="400"

        <PasswordBox.Style>
            <Style TargetType="PasswordBox">
                <Setter Property="Visibility" Value="Visible" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=chkShowPassword, Path=IsChecked}" Value="True">
                        <Setter Property="Visibility" Value="Hidden"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </PasswordBox.Style>
        

        </PasswordBox>

        <TextBox
        Grid.Row="0"
        Grid.Column="0"
        Text="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        TabIndex="2"
        Width="400"

        <TextBox.Style>
            <Style TargetType="TextBox" BasedOn="{StaticResource textBoxStyle}">
                <Setter Property="Visibility" Value="Hidden" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=chkShowPassword, Path=IsChecked}"  Value="True">
                        <Setter Property="Visibility" Value="Visible"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </TextBox.Style>
        

        </TextBox>


        "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

          The Visibility property set directly on the control overrides the value set by the style. You also have the trigger on the password box the wrong way round - you want to hide it when the checkbox is checked, not unchecked. And you have a typo in the binding for the textbox - IsCheckd instead of IsChecked. Change your code to:

          <PasswordBox
          Grid.Row="0"
          Grid.Column="0"
          TabIndex="2"
          cls:PasswordBoxAssistant.BindPassword="True"
          cls:PasswordBoxAssistant.BoundPassword="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
          Width="400"

          <PasswordBox.Style>
              <Style TargetType="PasswordBox">
                  <Setter Property="Visibility" Value="Visible" />
                  <Style.Triggers>
                      <DataTrigger Binding="{Binding ElementName=chkShowPassword, Path=IsChecked}" Value="True">
                          <Setter Property="Visibility" Value="Hidden"/>
                      </DataTrigger>
                  </Style.Triggers>
              </Style>
          </PasswordBox.Style>
          

          </PasswordBox>

          <TextBox
          Grid.Row="0"
          Grid.Column="0"
          Text="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
          TabIndex="2"
          Width="400"

          <TextBox.Style>
              <Style TargetType="TextBox" BasedOn="{StaticResource textBoxStyle}">
                  <Setter Property="Visibility" Value="Hidden" />
                  <Style.Triggers>
                      <DataTrigger Binding="{Binding ElementName=chkShowPassword, Path=IsChecked}"  Value="True">
                          <Setter Property="Visibility" Value="Visible"/>
                      </DataTrigger>
                  </Style.Triggers>
              </Style>
          </TextBox.Style>
          

          </TextBox>


          "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
          #4

          That did it. Thank you

          If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

          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