我创建了一个包含 ListBox 的 CustomMessageBox。由于某种原因,我在列表框(位于 CustomMessageBox 中)上的 SelectionChanged 事件没有触发。有什么建议么?
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;
}