public class VMTempTest : ViewModelBase
{
public VMTempTest()
{
CheckButtons = new List<CompBottonModel>()
{
new CompBottonModel(){ Content="苹果", IsCheck = false },
new CompBottonModel(){ Content="香蕉", IsCheck = false },
new CompBottonModel(){ Content="梨", IsCheck = false },
new CompBottonModel(){ Content="樱桃", IsCheck = false }
};
}
private List<CompBottonModel> checkButtons;
/// <summary>
/// 组合复选框
/// </summary>
public List<CompBottonModel> CheckButtons
{
get { return checkButtons; }
set
{
checkButtons = value; RaisePropertyChanged(() => CheckButtons);
}
}
private String checkInfo;
/// <summary>
/// 确认框选中信息
/// </summary>
public String CheckInfo
{
get { return checkInfo; }
set { checkInfo = value; RaisePropertyChanged(() => CheckInfo); }
}
private RelayCommand checkCommand;
/// <summary>
/// 复选框命令
/// </summary>
public RelayCommand CheckCommand
{
get
{
if (checkCommand == null)
checkCommand = new RelayCommand(() => ExcuteCheckCommand());
return checkCommand;
}
set { checkCommand = value; }
}
private void ExcuteCheckCommand()
{
CheckInfo = "";
if (CheckButtons != null && CheckButtons.Count > 0)
{
var list = CheckButtons.Where(p => p.IsCheck);
if (list.Count() > 0)
{
foreach (var l in list)
{
CheckInfo += l.Content + ",";
}
CheckInfo = CheckInfo.TrimEnd(','); // 把最后一个逗号删掉
}
}
}
}