Windows手机自定义消息框内容事件未触发

时间:2013-04-11 08:35:36

标签: xaml listbox windows-phone-8 selectionchanged

我创建了一个包含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;
}

0 个答案:

没有答案