Hi,
try following demo based on your code::
XAML:
<Window x:Class="WpfApp1.Window063"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp063"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="Window063" Height="450" Width="800">
<Window.DataContext>
<local:MyViewModel/>
</Window.DataContext>
<Window.Resources>
<ObjectDataProvider x:Key="Codes"
MethodName="GetValues"
ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="local:ProdCode"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<StackPanel>
<ComboBox ItemsSource="{Binding Source={StaticResource Codes}}"
SelectedItem="{Binding SelectedItem}"/>
<Button Command="{Binding ProdNavCommand}" Content="Check"/>
</StackPanel>
</Window>
And code:
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace WpfApp063
{
public class MyViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public ICommand ProdNavCommand { get; set; }
public ProdCode SelectedItem { get; set; }
private void OnPropertyChanged(string propertyName) =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
public MyViewModel()
{
ProdNavCommand = new MyCommand((state) => MessageBox.Show(string.Format("You select: " + SelectedItem), "Goes to..."));
}
}
public enum ProdCode
{
[Description("PersonalLoan")]
PersonalLoan,
[Description("Mortgage")]
Mortgage,
[Description("AutoLoan")]
AutoLoan
}
class MyCommand : ICommand
{
public event EventHandler CanExecuteChanged;
private Action<ComboBoxItem> _execute;
public MyCommand(Action<ComboBoxItem> execute) => _execute = execute;
public bool CanExecute(object parameter) => true;
public void Execute(object parameter)
{
var value = parameter as ComboBoxItem;
_execute.Invoke(value);
}
}
}
Result:
]1