0

When I need to binding a enum to RadioButton , Reference the How to bind RadioButtons to an enum? question's better answer.

enum code:

public enum SelectionMode
{
    FixedMode = 0,
    FreeMode = 1
}

/// <summary>
/// MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }
}

xaml code:

<RadioButton Content="FreeMode" IsChecked="{Binding ChannelSelectionMode, Converter={StaticResource enumToBooleanConverter}, ConverterParameter={x:Static local:SelectionMode.FreeMode}}" ></RadioButton>

I've got this exception :

xaml exception: namaspace not found the SelectionMode, the enum SelectionMode in the namespace, x:Type Local:SelectionMode can be work.

I tried this way:

  1. move enum SelectionMode to Viewmodels's namespace.
  2. move enum SelectionMode into one Viewmodel class.

but all not work. Please give me some sugguestion, I am crazy.

Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
Men Chuan
  • 39
  • 4

2 Answers2

0

The post you shared has converter code or you can find here in this post as well. Binding radio button to enum property.

Also you need to add another radio button something like this

<RadioButton Content="FixedMode" IsChecked="{Binding ChannelSelectionMode, Converter={StaticResource enumToBooleanConverter}, ConverterParameter={x:Static local:SelectionMode.FixedMode}}" ></RadioButton>
<RadioButton Content="FreeMode" IsChecked="{Binding ChannelSelectionMode, Converter={StaticResource enumToBooleanConverter}, ConverterParameter={x:Static local:SelectionMode.FreeMode}}" ></RadioButton>
Community
  • 1
  • 1
devil_coder
  • 1,115
  • 1
  • 9
  • 12
  • Thanks for your answer, in the moming I rebuild once agin. It works, eh....Most time restart VS would be a good way. [Laugh and cry] – Men Chuan Mar 24 '17 at 01:04
0

If you have a problem, don't worry, restart VS, leave for a while and then come back

Men Chuan
  • 39
  • 4