新しい VB.Net WPF アプリケーションがあります。MainWindow.xaml には、1 つの「テスト」ボタンしか含まれていません。
<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
これをビルドすると、コンパイルされません。私が得るエラーメッセージは次のとおりです。
Handles 句には、含まれている型またはその基本型のいずれかで定義された WithEvents 変数が必要です。
View 名前空間から MainWindow を削除すると、すべて問題ありません。したがって、明らかに名前空間が問題です。Window を名前空間に追加できますか?それを機能させるには、アプリケーション内の何かを変更する必要がありますか?