I have a TextBox
<TextBox x:Name="searchTextBox" Width="200" Height="30" HorizontalAlignment="Left"/>
and two Buttons
<Button x:Name="previous" Style="{StaticResource AppBarButtonStyle}" Tapped="OnOptionItemTapped" IsEnabled="False">
<Image Source="/Assets/images/left_arrow.png"/>
</Button>
<Button x:Name="next" Style="{StaticResource AppBarButtonStyle}" Tapped="OnOptionItemTapped" IsEnabled="False">
<Image Source="/Assets/images/right_arrow.png"/>
</Button>
Is there a simple solution to enable/disable the Buttons trough the TextBox?
Like for example if the TextBox is empty the Buttons are disabled. And if the TextBox is not empty the Buttons are enabled.
You could apply a text changed event that checks the input every time it changes.
<TextBox x:Name="searchTextBox" Width="200" Height="30" HorizontalAlignment="Left" TextChanged="TextBox_TextChanged" />
If the text is the way you need it, you can turn the button enabled/disabled.
public void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (searchTextBox.Text == result)
next.IsEnabled = false;
}
EDIT: Other than code behind like this approach you could learn about the MVVM design pattern. The other answers partly used practices common in MVVM.
There are various good tutorials for this all around the web.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With