我创建了一个包含ListBox的CustomMessageBox。由于某种原因,列表框上的SelectionChanged事件(在CustomMessageBox中)不会触发。有什么建议吗?
private void lstVehicle_SelectionChanged(object sender, SelectionChangedEventArgs e) {
ListBox _list = (ListBox)sender;
HyperlinkButton _button = (HyperlinkButton)_list.SelectedItem;
}
private void SelectVehicle() {
ListBox _list = new ListBox();
_list.ItemTemplate = CreateDataTemplate();
_list.ItemsSource = ManageStorage.vehicles;
_list.SelectionChanged += lstVehicle_SelectionChanged;
CustomMessageBox customMessageBox = new CustomMessageBox() { Message = "Select a vehicle from the list", Content = _list };
customMessageBox.Show();
}
private DataTemplate CreateDataTemplate() {
string xaml = @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Grid>
<HyperlinkButton Content='{Binding Make}' ></HyperlinkButton>
</Grid>
</DataTemplate>";
DataTemplate dt = (DataTemplate)System.Windows.Markup.XamlReader.Load(xaml);
return dt;
}