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