Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8635705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:02:45+00:00 2026-06-12T10:02:45+00:00

I have a toggle buttons in my wpf application. On startup the togglebutton must

  • 0

I have a toggle buttons in my wpf application. On startup the togglebutton must be set.

My Xaml File:

<ToggleButton Content="AUD Reset" IsChecked="True" Height="23" HorizontalAlignment="Center" Margin="0" Name="button4" Command="{Binding Path=ConnectCommand}" VerticalAlignment="Center" Width="100" />                   

On togglebutton click I want to check for the toggle state in my viewmodel class and if it returns true then I want to do the following operation:

My ViewModel Class:

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);
    }

How can I check whether the togglebutton is checked or not in my viewmodel and perform the above statements.

Please help!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:02:46+00:00Added an answer on June 12, 2026 at 10:02 am

    You can add IsChecked property to your ViewModel and bind it with ToggleButton.IsChecked dependency property:

    public bool IsChecked {
       get { return this.isChecked; }
       set {
          this.isChecked = value;
          this.OnPropertyChanged("IsChecked");
       }
    }
    
    <ToggleButton Content="AUD Reset" IsChecked="{Binding Path=IsChecked}" Height="23" HorizontalAlignment="Center" Margin="0" Name="button4" Command={Binding Path=ConnectCommand} VerticalAlignment="Center" Width="100" />    
    

    Then check its state:

    public void ConnectToSelectedDevice()
    {
        mComm.SetAddress(0x40);
        Byte[] buffer= new Byte[2];
        buffer[0] = 0x24;
        buffer[1] = 0x00;
    
        if(this.IsChecked)
        {
         buffer[1] = 0x04;
        }
        mComm.WriteBytes(2, buffer);
    }
    

    And finally, initialize IsChecked property in ViewModel’s constructor:

    public ViewModel() {
       this.IsChecked = true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want my WPF application to have a ToggleButton that contains an image of
I have a group of buttons that should act like toggle buttons, but also
I have a WPF application. In one window there is a combobox..and I want
I have a WPF application with ListBox that display list of items. Each item
Not sure how to word this algorithm question, actually. I have toggle buttons in
In my WPF application, I have an editable combo box with 150px fixed width.
I have two toggle buttons that I want to link together so that pressing
I have a toggle buttons group with 4 different pointers When I select the
I'm trying to set the DataContext of several toggle buttons, each of which will
I am using C# and WPF and I basically want to have some toggle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.