locked
Get selected items in combobox inside hub?

    Question

  • <hub> <HubSection> <DataTemplate> <ComboBox x:Name="comblevel" ItemsSource="{Binding Source={StaticResource combolevel}}" DisplayMemberPath="level" SelectionChanged="comblevel_SelectionChanged"> .....

    Get items to combobox:

    private  void LevelCombobox()
        {
            var Items = effort.query_level();
            combolevel.Source = Items;
        }

    And

    private void comblevel_SelectionChanged(object sender, SelectionChangedEventArgs e) { var items = ((ComboBox)sender).DataContext as ViewModel.EffortCombobox; }

    Items is null. How ways to get item when selected items on combobox? 

    could not called x:Name="comblevel" because of it be stay in hub.

    Monday, April 27, 2015 2:27 PM

Answers

  • Hi Greg Herney,

    >>How ways to get item when selected items on combobox? 

    Since I do not have all your code, first please try to remove the as statement in the this code ((ComboBox)sender).DataContext as ViewModel.EffortCombobox to see if you can get the result. Besides, I have defined the following class for data binding:

     public class TestComboBox
        {
            public string level { get; set; }
        }
    After that we can use the following code to get the selected item on ComboBox:
    var items = ((ComboBox)sender).SelectedItem as TestComboBox;
    string SelectedItem = items.level.ToString();

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, April 28, 2015 4:58 AM
    Moderator