WPF DataTrigger 改变控件颜色
之前这篇博文,用 True
和 False
两种情况来进行判断,其实也可以用 int 类型进行多个条件的判断。
XAML:
ViewModel:
public class TestVM : ViewModelBase
{
private int _PresentColor = 0;
public int PresentColor
{
get { return _PresentColor; }
set { _PresentColor = value; RaisePropertyChanged(nameof(PresentColor)); }
}
private RelayCommand _changeColorCommand;
public RelayCommand ChangeColorCommand
{
get {
if (_changeColorCommand == null)
_changeColorCommand = new RelayCommand(ChangeColor);
return _changeColorCommand; }
set { _changeColorCommand = value; RaisePropertyChanged(nameof(ChangeColorCommand)); }
}
private void ChangeColor()
{
if (PresentColor < 2)
PresentColor++;
else
PresentColor = 0;
}
}
原文:https://www.cnblogs.com/huvjie/p/15265426.html