How to restrain Action 'enabler'?

Topics: Actions & Coroutines, Conventions
Nov 6, 2011 at 8:13 PM

I have a view with a listbox, and a button. The view is simply to allow a user to select a value from a list, then proceed to the next view.

The list is bound to an Enumerable in the view-model, and has an attached action.

(from memory)

ListBox:
cal:Message.Attach="[MouseDoubleClick] = [MoveNext]" // this allows the user to simply doubleclick an item in the list to proceed

Button:
cal:Message.Attach="[MoveNext]"

 

I want the button disabled when nothing in the list is selected - forcing the user to select something.

So, I added this to the view-model

public bool CanMoveNext()
... 

The problem is the 'CanMoveNext' is being applied to both the button, AND the listbox, resulting in both the listbox and button being disabled, the user cannot select an item to proceed.

I have gotten around this by not using the 'CanMoveNext' convention, but I would prefer to use it if I could...

Is there something Im missing?

 

Thanks

Nov 6, 2011 at 11:27 PM

instead of CanMoveNext being a method make it a property and when ever your selected item changes throw a notification to CanMoveNext, this will in turn enable the button and allow the user to proceed.

public SomeObject SelectedObject{
   get{ return _selectedObject;}
   set {   _selectedObject = value;
            NotifyOfPropertyChange(()=>SelectedObject);
            NotifyOfPropertyChange(() => CanMoveNext);
    }
}

NotifyOfPropertyChange(()=> CanMoveNext);

public bool CanMoveNext {
   get{ return _selectedObject != null;}
}

not sure if this will work for your implementation or not...

 

 

 

Nov 6, 2011 at 11:50 PM
Hi mvermef,

Yes, that's exactly what I am doing at the moment - I was hoping there was something in the syntax that I could use to not need this work-around.

Thanks

On Mon, Nov 7, 2011 at 12:27 PM, mvermef <notifications@codeplex.com> wrote:

From: mvermef

instead of CanMoveNext being a method make it a property and when ever your selected item changes throw a notification to CanMoveNext, this will in turn enable the button and allow the user to proceed.

public SomeObject SelectedObject{
get{ return _selectedObject;}
set { _selectedObject = value;
NotifyOfPropertyChange(()=>SelectedObject);
NotifyOfPropertyChange(() => CanMoveNext);
}
}

NotifyOfPropertyChange(()=> CanMoveNext);

public bool CanMoveNext {
get{ return _selectedObject != null;}
}

not sure if this will work for your implementation or not...

Read the full discussion online.

To add a post to this discussion, reply to this email (caliburnmicro@discussions.codeplex.com)

To start a new discussion for this project, email caliburnmicro@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Nov 7, 2011 at 3:47 PM

the only other thing to do would be to use different methods for the respective events, unless someone else has an alternative, I can't think of it right now...