【发布时间】:2014-10-22 21:57:13
【问题描述】:
我正在尝试制作一个计算器,这是我第一次使用带有 GUI 的任何东西进行编码
我正在通过 C# 应用程序使用 Visual Studio 2012 WPF
如何将按钮内容获取到计算器文本框(屏幕)?
XAML:
<Button x:Name="one" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
Foreground="White" FontSize="20" FontWeight="Bold" Width="50" Height="41"
Content="1" Margin="31,350,491,64" Click="button_Click"
HorizontalAlignment="Left" VerticalAlignment="Bottom"/>
C#:
private void button_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
screen.Text = screen.Text + b.Text;
}
它在 b 旁边的文本下划线。
错误 1“System.Windows.Controls.Button”不包含“Text”的定义,并且找不到接受“System.Windows.Controls.Button”类型的第一个参数的扩展方法“Text”(是您缺少 using 指令或程序集引用?)
【问题讨论】:
-
有些不对劲?应该是
void button_Click(object sender, RoutedEventArgs e)吗?
标签: c# wpf xaml button textbox