baueric
baueric

Reputation: 386

Visual Studio WPF designer crashes when using a + in a binding

My Visual Studio 2010 designer crashes with this error:

Error   3   Type 'vm:MessageViewModel+MessageAction' was not found.

This is the line causing the error:

<Button Content="View" Command="{Binding Path=ActionCommand}" CommandParameter="{x:Static vm:MessageViewModel+MessageAction.OpenView}"/>

Keep in mind the program compiles and runs fine. The parameter is even passed correctly to the command.

The enum is inside a class so I need to use the plus sign to reference it. This is the class structure:

public class MessageViewModel : ModelWrapViewModel<MessageModel>
{
    private ICommand _actionCommand;

    public enum MessageAction
    {
        OpenView,
        OpenNote,
        OpenAcknowledge,
        Cancel,
        Save,
        Acknowledge
    }

    public ICommand ActionCommand
    {
        get
        {
            if (_actionCommand == null)
            {
                _actionCommand = new RelayCommand(
                    param => this.DoSomething((MessageAction)param),
                    param => true
                );
            }
            return _actionCommand;
        }
    }

}

Just wondering if there is a reason this doesn't work in the VS designer. If I move the enum outside of the of the MessageViewModel class the designer doesn't crash.

Upvotes: 0

Views: 229

Answers (1)

Rick
Rick

Reputation: 65

visual studio can be a pain sometimes no? Not sure if this will help but can you make it a Dynamic Resource so it only loads at run time. Hope this helps - Rick CommandParameter="{DynamicResource {x:Static vm:MessageViewModel+MessageAction.OpenView}}"/>

Upvotes: 1

Related Questions