Hey I just started working on Toggle Buttons and I have set the properties of the button. I want to check for the toggle state which should return me 1 or 0.
XAML:
<ToggleButton Grid.Column="3" Content="On" Command="{Binding VoltageToggleCommand}" IsChecked="{Binding Path=IsChecked}" Name="VoltageToggleBtn" />
ViewModel Class:
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
}
Thus when I click the toggle button, controls reaches ToggleButtonCommandExecuted() where I need to check for the state and store it in cmdArray. Basically when code is executed cmdArray[numBytes++] = 1 or 0.
How can I achieve it? 🙂
you will have to convert from boolean to byte yourself