我有一个资源字典:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="wpfUI2.MainWindowEvents">
<DataTemplate
x:Key="WorkspacesTemplate">
<TabControl
x:Name="Tab1"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding}"
ItemTemplate="{StaticResource ClosableTabItemTemplate}"
Margin="4"/>
</DataTemplate>
...
我想为TabControl添加一个事件处理程序。 MainWindowEvents是在没有其他类的文件中定义的类:
Namespace wpfUI2
Public Class MainWindowEvents
End Class
End Namespace
当我要添加事件处理程序时,例如:
<TabControl
x:Name="Tab1"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding}"
ItemTemplate="{StaticResource ClosableTabItemTemplate}"
Margin="4"
SelectionChanged=""
/>
尝试在""之间单击以创建事件时,我收到一个错误,指定x:Class属性的类必须是文件中的第一项。好吧,它就是!奇怪的是,当我手动创建处理程序时:
Namespace wpfUI2
Public Class MainWindowEvents
Public Sub Tab1_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)
End Sub
End Class
End Namespace
所有的编译都没问题,但在 window.show 上运行时出现异常。
我做错了什么?