XAML:
<Grid>
<Button Content="√" HorizontalAlignment="Left" Margin="145,10,0,0" VerticalAlignment="Top" Width="75"
Click="OnSquareRootClick"/>
<TextBox x:Name="txtNumber" HorizontalAlignment="Left" Height="23" Margin="10,10,0,0" Text="" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="txtResult" HorizontalAlignment="Left" Height="23" Margin="240,10,0,0" Text="" VerticalAlignment="Top" Width="120"/>
</Grid>
Code Behind:
private void OnSquareRootClick(object sender, RoutedEventArgs e)
{
double number;
var isDouble = double.TryParse(this.txtNumber.Text, out number);
if (isDouble)
{
this.txtResult.Text =
string.Format(
"{0}{1} = {2}",
"\u221A",
this.txtNumber.Text,
Math.Round(Math.Sqrt(number), 2));
}
}
4
solved How to add sqrt in WPF calculator c# [closed]