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 8659755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:05:10+00:00 2026-06-12T16:05:10+00:00

I have 2 comboboxes in my xaml file. Basically when we double click the

  • 0

I have 2 comboboxes in my xaml file. Basically when we double click the combobox in xaml file, it creates a combobox_selectionchanged event in xaml.cs file. I have done it as follows:

View Class:

<ComboBox Height="23" ItemsSource="{Binding BusRateList}" SelectedItem="{Binding SelectedBusRateItem}" SelectedIndex="2"  Name="comboBox2" SelectionChanged="comboBox2_SelectionChanged" />

<ComboBox Height="23" ItemsSource="{Binding BaudRateList}" SelectedItem="{Binding SelectedBaudRateItem}" SelectedIndex="6" Name="comboBox3" SelectionChanged="comboBox3_SelectionChanged" />

View.xaml.cs file:

private void comboBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        int id = Convert.ToInt32(comboBox2.SelectedIndex);            
        int speed = mI2c._busRate[id]; //mI2C is object of viewmodel class

        sendBuf[0] = Convert.ToByte((speed & 0xFF000000) >> 24);
        sendBuf[1] = Convert.ToByte((speed & 0x00FF0000) >> 16);
        sendBuf[2] = Convert.ToByte((speed & 0x0000FF00) >> 8);
        sendBuf[3] = Convert.ToByte(speed & 0x000000FF);

        cmd = (256 << 8 | 0x00);
        mCom.WriteInternalCommand(cmd, 4, ref sendBuf);

        ReadBusAndBaudRate();            
    }


private void comboBox3_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        int id = Convert.ToInt32(comboBox3.SelectedIndex);            
        int speed = mI2c._baudRate[id]; //mI2C is object of viewmodel class
        sendBuf[0] = Convert.ToByte((speed & 0xFF000000) >> 24);
        sendBuf[1] = Convert.ToByte((speed & 0x00FF0000) >> 16);
        sendBuf[2] = Convert.ToByte((speed & 0x0000FF00) >> 8);
        sendBuf[3] = Convert.ToByte(speed & 0x000000FF);

        cmd = (256 << 8 | 0x00);
        mCom.WriteInternalCommand(cmd, 4, ref sendBuf);

        ReadBusAndBaudRate();
    }

public void ReadBusAndBaudRate()
    {          

        int speed = 100;

        // Some Code

        textBox1.Text = speed.ToString();

        textBox2.Text = speed.ToString();

        // Update message in Output Window as Effective Baud Rate
    }

ViewModel Class:

public ObservableCollection<int> _busRate;
public ObservableCollection<int> BusRateList
    {
        get { return _busRate; }
        set
        {
            _busRate = value;
            NotifyPropertyChanged("BusRateList");
        }
    }

    private int _selectedBusRate;
    public int SelectedBusRateItem
    {
        get { return _selectedBusRate; }
        set
        {
            _selectedBusRate = value;
            NotifyPropertyChanged("SelectedBusRateItem");
        }
    }      

    public ObservableCollection<int> _baudRate;
    public ObservableCollection<int> BaudRateList
    {
        get { return _baudRate; }
        set
        {
            _baudRate = value;
            NotifyPropertyChanged("BusRateList");
        }
    }

    private int _selectedBaudRate;
    public int SelectedBaudRateItem
    {
        get { return _selectedBaudRate; }
        set
        {
            _selectedBaudRate = value;
            NotifyPropertyChanged("SelectedBaudRateItem");
        }
    }

I have added around 8 items in both comboboxes in viewmodel constructor.

Now Using the above properties I want to perform the combobox selection changed event in viewmodel class which should execute all the statements which were done in my .cs file.

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-12T16:05:11+00:00Added an answer on June 12, 2026 at 4:05 pm

    Update viewmodel with ReadBusAndBaudRate() method and call this method in set of SelectedItem properties

    public int SelectedBusRateItem
        {
            get { return _selectedBusRate; }
            set
            {
                _selectedBusRate = value;
                 ReadBusAndBaudRate();
                NotifyPropertyChanged("SelectedBusRateItem");
            }
        }
        private int _selectedBaudRate;
        public int SelectedBaudRateItem
        {
            get { return _selectedBaudRate; }
            set
            {
                _selectedBaudRate = value;
                ReadBusAndBaudRate();
                NotifyPropertyChanged("SelectedBaudRateItem");
            }
        }
    
        private int _speed;
        public int Speed
        {
            get { return _speed; }
            set
            {
                _speed = value;
                NotifyPropertyChanged("Speed");
            }
        }
    
    
        private void ReadBusAndBaudRate()
        {
            //Do some code
            Speed = 10; // will be your logical value.
            //For message notifications use MVVM frameworks such as cinch by Sacha Barber
        }
    
    • Update xaml with Binding Mode and TextBox binding for speed

    • Add method fo mcom stuff as

        public int SelectedBaudRateItem
          {
              get { return _selectedBaudRate; }
              set
              {
                  _selectedBaudRate = value;                   
                  WriteMcomCommand(_selectedBaudRate );
                  ReadBusAndBaudRate();
                  NotifyPropertyChanged("SelectedBaudRateItem");
              }
          }    
          private void WriteMcomCommand(int id)
          {
          int speed = mI2c._busRate[id]; //mI2C is object of viewmodel class
      
          sendBuf[0] = Convert.ToByte((speed & 0xFF000000) >> 24);
          sendBuf[1] = Convert.ToByte((speed & 0x00FF0000) >> 16);
          sendBuf[2] = Convert.ToByte((speed & 0x0000FF00) >> 8);
          sendBuf[3] = Convert.ToByte(speed & 0x000000FF);
      
          cmd = (256 << 8 | 0x00);
          mCom.WriteInternalCommand(cmd, 4, ref sendBuf);
          }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following App.xaml file: <Application x:Class=MiniDeviceConfig.App xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml StartupUri=MiniDeviceConfig.xaml> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries>
I have difficulties in binding the follow structures to XAML View: public class SampleViewModel
I have a ComboBox whose xaml is as follows <ComboBox Name=ComboBoxDiscussionType IsEnabled={Binding ElementName=ComboBoxDiscussionType, Path=Items.Count,
I have the following definition in my xaml file to bind a combobox to
I have a xaml file looking like this. <Window x:Class=Space4it.Energilab.DataApplicationWPF.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:sys=clr-namespace:System;assembly=mscorlib xmlns:local=clr-namespace:Space4it.Energilab.DataApplicationWPF
I have XAML File as below: <Window x:Class=ComboBoxCheck.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:check=clr-namespace:ComboBoxCheck Title=Window1 Height=300 Width=320>
I have two related ComboBoxes ( continents, and countries ). When the continents ComboBox
I'm learning MVVM. I have my View filling two comboboxes from ObservableCollection properties in
In XAML I have a combobox defined as: <ComboBox x:Name=UsernameComboBox ItemsSource={Binding Users} DisplayMemberPath=Username SelectedItem={Binding
I currently have a Combobox like the following: //XAML <ComboBox> <ComboBoxItem> Awake & Alive</ComboBoxItem>

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.