What is the right way to do this? This way is not working:
if (((String)enterAmountButton.Content) == "")
MessageBox.Show("Please enter the total bill amount.");
else if (((String)enterTipButton.Content) == "")
MessageBox.Show("Please enter the tip % amount.");
this way is not working neither:
if (enterAmountButton.Content == "")
MessageBox.Show("Please enter the total bill amount.");
else if (enterTipButton.Content == "")
MessageBox.Show("Please enter the tip % amount.");
would work. However, how are you expecting to get the strings? you most likely want the value in a TextBox that is next to the button, correct?
in that case:
where
amountTextBox&tipTextBoxare thex:Nameof yourTextBoxes.One last thing:
There’s probably a better way to handle this. For example, if you handle the KeyUp & TextChanged events on the TextBoxes and only Enable the button when text exists (even better, valid text ;))
You could use a converter too:
Add a reference to your converter
<Converters:StringToEnabledConverter x:Key="StringToEnabledConverter" />and on your button,