How to implement Multistate CheckBox in WPF for MVVM
I have a requirement for which i need a MultiState Checkboxes in WPF...
Also as i am using MVVM so handling bindi开发者_运维技巧ng 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...
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;
}
}
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;
精彩评论