Вы можете добавить прослушиватель для события SelectionChanged
и обработать выбор пользователя.
XAML:
<ComboBox SelectionChanged="ComboBoxSelectionChanged">
<ComboBoxItem Tag="UsersWindow">Users Window</ComboBoxItem>
<ComboBoxItem Tag="SettingsWindow">Settings Window</ComboBoxItem>
<ComboBoxItem Tag="CustomersWindow">Customers Window</ComboBoxItem>
</ComboBox>
Кодовый код
public partial class MainWindow
{
public List<Window> Windows { get; set; }
public MainWindow()
{
InitializeComponent();
Windows = new List<Window>
{
new Window { Name = "UsersWindow" },
new Window { Name = "SettingsWindow" },
new Window { Name = "CustomersWindow" },
};
}
private void ComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var comboBox = (ComboBox)e.Source;
if (comboBox.SelectedItem == null) return;
var selectedItem = (ComboBoxItem)comboBox.SelectedItem;
var window = Windows.FirstOrDefault(w => w.Name.Equals(selectedItem.Tag));
if (window == null) return;
window.ShowDialog();
}
}