嘿,我刚开始研究切换按钮,我已经设置了按钮的属性。我想检查应该返回 1 或 0 的切换状态。
XAML:
<ToggleButton Grid.Column="3" Content="On" Command="{Binding VoltageToggleCommand}" IsChecked="{Binding Path=IsChecked}" Name="VoltageToggleBtn" />
视图模型类:
private ICommand mToggleButtonCommand;
public ICommand VoltageToggleCommand
{
get
{
if (mToggleButtonCommand == null)
mToggleButtonCommand = new DelegateCommand(new Action(ToggleButtonCommandExecuted), new Func<bool>(ToggleButtonCommandCanExecute));
return mToggleButtonCommand;
}
set
{
mToggleButtonCommand = value;
}
}
/// <summary>
/// Check for ToggleButton State
/// </summary>
private bool isChecked;
public bool IsChecked
{
get { return this.isChecked; }
set
{
this.isChecked = value;
this.OnPropertyChanged("IsChecked");
}
}
public bool ToggleButtonCommandCanExecute()
{
return true;
}
public void ToggleButtonCommandExecuted()
{
Byte[] cmdArray = new Byte[256];
int numBytes = 0;
cmdArray[numBytes++] = // Here I wanna retrieve the toggle state i.e. 1 or 0
// Some Code
}
因此,当我单击切换按钮时,控件到达ToggleButtonCommandExecuted()
我需要检查状态并将其存储在cmdArray
. 基本上在执行代码时 cmdArray[numBytes++] = 1 或 0。
我怎样才能实现它?:)