1
我有一个新的VB.Net WPF应用程序。该MainWindow.xaml包含无非一个 '测试' 按钮更多:Visual Basic .NET:名称空间中的WPF窗口
<Window x:Class="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>
<Button Content="Test"
Name="btnTest" />
</Grid>
</Window>
的Application.xaml是不变:
<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
后面的代码如下所示。我所做的只是双击按钮,以便事件处理程序自动添加。我还将MainWindow添加到View命名空间。
Namespace View
Class MainWindow
' A test button on the main window
Private Sub btnTest_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnTest.Click
MessageBox.Show("Hello world!")
End Sub
End Class
End Namespace
当我构建它时,它不编译。我得到的错误消息是:
句柄子句需要在包含类型或其基类型中定义的WithEvents变量。
当我从View命名空间中删除MainWindow时,一切都很好。很显然,命名空间是一个问题。我可以向命名空间添加一个窗口,并且是否需要在应用程序中更改其他内容以使其正常工作?