Where do methods (such as OnSelectionChange) for a combo box that is nested in a dockpane go?

06-03-2019 10:14 AM
New Contributor III

There is plenty of documentation on how to add combo boxes to a toolbar/group from the daml and how to add functionality in the corresponding .cs file.  However, I haven't been able to find any documentation on how to put a combobox in the .xaml file for a dockpane and reference methods.

The method I would like to reference is OnSelectionChange:

I have my combobox declared in the .xaml

<DockPanel Grid.Row="2" Grid.Column="1">
<ComboBox Name ="ProfileBox"
Width="Auto" Height="Auto" IsEditable="True" Background="{DynamicResource Esri_BackgroundPressedBrush}" ItemsSource="{Binding Profiles}"
Foreground="{DynamicResource Esri_TextMenuBrush}">


and I am able to add items to a list and pass them as the source:

foreach (var item in profileRead)
string name = Path.GetFileNameWithoutExtension(item);


private ObservableCollection<string> _profiles = new ObservableCollection<string>();

public ObservableCollection<string> Profiles
SetProperty(ref _profiles, value, () => Profiles);
NotifyPropertyChanged(() => Profiles);

get { return _profiles; }


I was able to reference the selection from the xaml.cs file:

public partial class Dockpane1View : UserControl
public static ComboBox profileBoxRef = new ComboBox();

public Dockpane1View()
profileBoxRef = ProfileBox;



However, I cannot figure out how to implement OnSelectionChange. 



2 Replies
Regular Contributor

Hi John,

If you do not use MVVM then you could add event to your xaml file like this:

<ComboBox x:Name="cbLayer" Margin="10" Width="150" SelectionChanged="Layer_SelectionChanged">

In xaml.cs you need to add method for SelectionChanged:

private void Layer_SelectionChanged(object sender, SelectionChangedEventArgs e)

In MVVM you do not need OnSelectionChange. You need to create property for SelectedItem or SelectedValue in your model view file and make binding in xaml

<ComboBox ItemsSource="{Binding Layers}" SelectedItem="{Binding SelectedLayer}"/>


New Contributor III


That worked like a charm, thank you!!


0 Kudos