【发布时间】:2014-06-12 13:30:24
【问题描述】:
我正在尝试创建一个非常简单的 C# 程序。
这是 xaml 文件:
<Window x:Class="HelloWPFApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBlock HorizontalAlignment="Left" Margin="104,72,0,0" TextWrapping="Wrap" Text="Select a message option and then choose the Display button" VerticalAlignment="Top"/>
<RadioButton x:Name="RadioButton1" Content="Hello;" HorizontalAlignment="Left" Margin="104,138,0,0" VerticalAlignment="Top" Checked="RadioButton1_Checked"/>
<RadioButton x:Name="RadioButton2" Content="Goodbye;" HorizontalAlignment="Left" Margin="342,138,0,0" VerticalAlignment="Top"/>
<Button Content="Display" HorizontalAlignment="Left" Margin="211,208,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
</Grid>
</Window>
这是 .cs 文件:
using....
namespace HelloWPFApp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (RadioButton1.IsChecked == true)
MessageBox.Show("Hello");
else
MessageBox.Show("Goodbye");
}
}
}
这是我得到的错误:
'HelloWPFApp.MainWindow' 不包含 'RadioButton1_Checked' 并且没有扩展方法 'RadioButton1_Checked' 接受“HelloWPFApp.MainWindow”类型的第一个参数可能是 找到(您是否缺少 using 指令或程序集引用?)
你能告诉我问题是什么吗?
【问题讨论】:
-
您的 XAML 包含
Checked="RadioButton1_Checked"而您的代码隐藏类中没有该方法。