0

I have following checkbox:

<dxe:CheckEdit Margin="2,0" IsChecked="{Binding SelectedContact.isMajor,Mode=TwoWay,Converter={StaticResource CheckBoxNullToFalse}}">More than 18</dxe:CheckEdit>

This is what i want to achieve: when the user clicks on the check box, i want to call a function but also assign the isMajor field.

The only way i see how to do this is to bind to a command that will perform both operations

Is there a more straightforward way ?
Thanks
John

1
  • What is isMajor Field, another check box or some field in your database ? Commented Nov 11, 2010 at 17:00

2 Answers 2

1

Make isMajor a property rather than a field, and call a method in the setter

private bool _isMajor;
public bool IsMajor
{
    get { return _isMajor; }
    set
    {
        _isMajor = value;
        OnPropertyChanged("IsMajor");
        DoSomething();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

To be honest, using a Command is the first thing that occurred to me. I assume that dxe:CheckEdit is some CheckBox variant - you might find a ToggleButton useful, as an alternative, depending on what behavior you're looking for.

I'm not sure what you mean by "straightforward" (least code, easiest to understand, etc.), but binding IsChecked to an isMajor property (as per @Thomas Levesque) and binding to a Command (Relay or Delegate, for example) to call the function provides a clean way to do both things that you want without introducing side-effects into your code, as you would if you called the function from a property setter or your Converter, for example, that wouldn't be obvious to other developers. Or to you, when you return to maintain this a year from now. :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.