<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions> <!--TitlePanel 包含应用程序的名称和页标题-->
<StackPanel Grid.Row="" Margin="12,17,0,28">
<TextBlock Text="我的应用程序" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="页面名称" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel> <!--ContentPanel - 在此处放置其他内容-->
<Grid x:Name="ContentPanel" Grid.Row="" Margin="12,0,12,0"> </Grid>
<Grid x:Name="MyGrid" HorizontalAlignment="Left" Height="" Margin="7,0,0,0" Grid.Row="" VerticalAlignment="Top" Width="">
<TextBlock x:Name="InputInformation" HorizontalAlignment="Left" Height="" TextWrapping="Wrap" VerticalAlignment="Top" Width="" FlowDirection="LeftToRight" TextAlignment="Right"/>
<TextBlock x:Name="OperationResult" HorizontalAlignment="Left" Height="" Margin="0,73,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="" FlowDirection="LeftToRight" TextAlignment="Right"/>
<Button x:Name="B0" Content="" HorizontalAlignment="Left" Height="" Margin="19,487,0,0" VerticalAlignment="Top" Width="" Click="Btn_ButClick"/>
<Button x:Name="Result" Content="=" HorizontalAlignment="Left" Height="" Margin="119,487,0,0" VerticalAlignment="Top" Width="" Click="ResultJG"/>
<Button x:Name="Del" Content="Del" HorizontalAlignment="Left" Height="" Margin="221,487,0,0" VerticalAlignment="Top" Width="" Click="Delclick"/>
<Button x:Name="Divide" Content="/" HorizontalAlignment="Left" Height="" Margin="321,487,0,0" VerticalAlignment="Top" Width="" RenderTransformOrigin="0.5,0.5" Click="YunSuan"/>
<Button x:Name="B1" Content="" HorizontalAlignment="Left" Height="" Margin="19,393,0,0" VerticalAlignment="Top" Width="" Click="Btn_ButClick"/>
<Button x:Name="B2" Content="" HorizontalAlignment="Left" Height="" Margin="119,393,0,0" VerticalAlignment="Top" Width="" Click="Btn_ButClick"/>
<Button x:Name="B3" Content="" HorizontalAlignment="Left" Height="" Margin="221,393,0,0" VerticalAlignment="Top" Width="" Click="Btn_ButClick"/>
<Button x:Name="Multiply" Content="*" HorizontalAlignment="Left" Height="" Margin="321,393,0,0" VerticalAlignment="Top" Width="" RenderTransformOrigin="0.5,0.5" Click="YunSuan"/>
<Button x:Name="B4" Content="" HorizontalAlignment="Left" Height="" Margin="19,299,0,0" VerticalAlignment="Top" Width="" Click="Btn_ButClick"/>
<Button x:Name="B5" Content="" HorizontalAlignment="Left" Height="" Margin="119,299,0,0" VerticalAlignment="Top" Width="" Click="Btn_ButClick"/>
<Button x:Name="B6" Content="" HorizontalAlignment="Left" Height="" Margin="221,299,0,0" VerticalAlignment="Top" Width="" Click="Btn_ButClick"/>
<Button x:Name="Minus" Content="-" HorizontalAlignment="Left" Height="" Margin="321,299,0,0" VerticalAlignment="Top" Width="" RenderTransformOrigin="0.5,0.5" Click="YunSuan"/>
<Button x:Name="B7" Content="" HorizontalAlignment="Left" Height="" Margin="19,205,0,0" VerticalAlignment="Top" Width="" Click="Btn_ButClick"/>
<Button x:Name="B8" Content="" HorizontalAlignment="Left" Height="" Margin="119,205,0,0" VerticalAlignment="Top" Width="" Click="Btn_ButClick"/>
<Button x:Name="B9" Content="" HorizontalAlignment="Left" Height="" Margin="221,205,0,0" VerticalAlignment="Top" Width="" Click="Btn_ButClick"/>
<Button x:Name="Plus" Content="+" HorizontalAlignment="Left" Height="" Margin="321,205,0,0" VerticalAlignment="Top" Width="" RenderTransformOrigin="0.5,0.5" Click="YunSuan"/>
</Grid>
</Grid>
namespace PhoneApp1
{
public partial class Calculator : PhoneApplicationPage
{
public string Operation = "";//记录一下之前一次按下的运算符
public double Num = ;//结果
public Calculator()
{
InitializeComponent();
} private void Btn_ButClick(object sender, RoutedEventArgs e)
{
if (Operation == "=")
{
OperationResult.Text = "";
InputInformation.Text = "";
Num = ;
}
string s = (sender as Button).Content.ToString();
OperationResult.Text = OperationResult.Text + s;
InputInformation.Text = InputInformation.Text + s;
} private void YunSuan(object sender, RoutedEventArgs e)
{
string fh= (sender as Button).Content.ToString();
OperationNum(fh);
InputInformation.Text = InputInformation.Text + fh;
OperationResult.Text = "" ;
} private void OperationNum(string fh)
{
if (OperationResult.Text != "")
{ if (Operation == "+")
{
Num = Num +double.Parse( OperationResult.Text.ToString());
Operation = fh;
}
else if (Operation == "-")
{
Num = Num - double.Parse(OperationResult.Text.ToString());
Operation = fh;
}
else if (Operation == "*")
{
Num = Num * double.Parse(OperationResult.Text.ToString());
Operation = fh;
}
else if (Operation == "/")
{
if (double.Parse(OperationResult.Text.ToString()) != )
Num = Num / double.Parse(OperationResult.Text.ToString());
else
Num = ;
Operation = fh;
}
else//(Operation=="" || Operation="=")
{
Num = double.Parse(OperationResult.Text.ToString());
Operation = fh;
}
}
} private void ResultJG(object sender, RoutedEventArgs e)
{
OperationNum("=");
OperationResult.Text = Num.ToString();
} private void Delclick(object sender, RoutedEventArgs e)
{
OperationResult.Text ="";
InputInformation.Text = "";
Num = ;
}
}
}
05-11 22:41