2

I have a requirement for which i need a MultiState Checkboxes in WPF...

Also as i am using MVVM so handling binding and Commands should follow the same as i will use it in my Views.

I have seen a Multistate checkbox in DotnetNuke(made in ASP.NET) but how to make it in WPF

some inputs in this regards will be helpful

Some example will be great...

5
  • There is no tag for Multistate Checkboxes in the site... o_O Commented Jun 10, 2011 at 13:31
  • So...which part are you struggling with? Commented Jun 10, 2011 at 13:47
  • I have to show change the Icon for 4 diferent states Agree,Disagree,Maybe,I Dont care..... Commented Jun 10, 2011 at 14:17
  • So....are you actually looking for Radio Buttons? Commented Jun 10, 2011 at 14:32
  • No a single checkBox will have Four states.... Clicking on it will toggle the four states : Agree,Disagree,Maybe,I dont know ... Commented Jun 10, 2011 at 14:50

2 Answers 2

2

Checkboxes have specific functionality (checked, unchecked, and optionally indeterminate).

Based on your comment, I would think it would be easiest to just do it as a button. I don't have time now to test out an actual example, but here some pseudocode to get you going:

XAML

<Button Command="{Binding ToggleDecisionState}">
    <Button.Content>
        <Image Source="{Binding CurrentDecisionIcon}" />
    <Button.Content>
</Button>

ViewModel (leaving out MVVM implementation details)

enum Decisions
{
    Agree,
    Disagree,
    Maybe,
    DoNotKnow
};

public Decisions CurrentDecision
{
    get {}
    set {}
}

public RelayCommand ToggleDecisionStateCommand
{
       // In here, call code to execute toggle
       if (mCurrentDecision == Decisions.DoNotKnow)
           CurrentDecision = Decisions.Agree;
       else
           CurrentDecision += 1;       
}

public ImageSource CurrentDecisionIcon
{
    get
    {
        ImageSource img = [some default image];
        switch (mCurrentDecision)
        {
            case Decisions.Agree:
                img = [path to Agree icon];
                break;

            // Other cases here
        }

        return img;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

if you want to use 3-state check box, you must change the behind boolean value(in ViewModel) to bool? type.

  public bool? IsEnabled { get; set; }

and Set this property for CheckBox

  IsThreeState = True;

1 Comment

I have to show change the Icon for 4 diferent states Agree,Disagree,Maybe,I Dont care.....

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.