1
我的wpf應用程序中有一個切換按鈕。在啓動時,必須設置togglebutton。在啓動時設置按鈕的ToggleState並檢查狀態
我的XAML文件:
<ToggleButton Content="AUD Reset" IsChecked="True" Height="23" HorizontalAlignment="Center" Margin="0" Name="button4" Command="{Binding Path=ConnectCommand}" VerticalAlignment="Center" Width="100" />
在切換按鈕點擊我想在我的ViewModel類來檢查切換狀態,如果返回true,則我想要做如下操作:
我ViewModel類:
private ICommand mUpdater;
public ICommand ConnectCommand
{
get
{
if (mUpdater == null)
mUpdater = new DelegateCommand(new Action(ConnectToSelectedDevice), new Func<bool>(ConnectCanExecute));
return mUpdater;
}
set
{
mUpdater = value;
}
}
public bool ConnectCanExecute()
{
return true;
}
public void ConnectToSelectedDevice()
{
mComm.SetAddress(0x40);
Byte[] buffer= new Byte[2];
buffer[0] = 0x24;
buffer[1] = 0x00;
if(Check if button togglestate is set, if true then)
{
buffer[1] = 0x04;
}
mComm.WriteBytes(2, buffer);
}
我如何檢查T是否他的togglebutton被檢查或不在我的viewmodel並執行上述語句。
請幫忙!!
真棒:)它的工作:)謝謝SHSE。 –