Reputation: 3276
Hi I have button that reads "True", When the user presses it, I want it to read "False". I have tried the following but it does not work. Can someone help please? Thanks
Private Sub buttonTrue_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles buttonTrue.Click
buttonTrue.Content = "False"
XML for button:
<Button Content="True" Grid.Row="1" Height="200" Margin="185,260,156,0" Name="buttonTrue" VerticalAlignment="Top" Background="Black" BorderThickness="3" BorderBrush="White" />
Upvotes: 2
Views: 784
Reputation: 16826
Your XAML does not have a Click
event handler. Add it: Click="buttonTrue_Click"
Upvotes: 1
Reputation: 1891
What you have looks to me like it should work. But the problem I see is that once the button is clicked, it should say false, and will never change after that, as you have no conditions.
There are a couple of other things I would consider, depending on what you're looking for.
One thing would be to look at a ToggleButton if you're looking for it to toggle between True and False. Bind the content to the state through a converter.
Another would be if you want the button to still appear the same as a regular button instead of a ToggleButton would (with one state showing a white background with black text). That would be to use a condition statement and again bind the content through a converter. For instance, set up a bool variable, and have the event change the state of that variable, and use NotifyPropertyChanged to update the UI.
Upvotes: 0