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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:51:01+00:00 2026-06-13T02:51:01+00:00

I am working on a WPF app where I need to work with comboboxes.

  • 0

I am working on a WPF app where I need to work with comboboxes. I need to add items in the combobox and set the selectedindex in xaml. I have done it successfully but SelectedIndex doesn’t appear when I run the application. Here is my code:

XAML:

<ComboBox Grid.Column="0" ItemsSource="{Binding FrequencyList}" SelectedItem="{Binding SelectedFrequencyList, Mode=TwoWay}" SelectedIndex="0" Name="comboBox1" />
<ComboBox Grid.Column="2" ItemsSource="{Binding ModesList}" SelectedItem="{Binding SelectedModesList, Mode=TwoWay}" SelectedIndex="2" Name="comboBox2" />

ViewModel:

public ObservableCollection<string> _FreqList;
_FreqList = new ObservableCollection<string>();
public ObservableCollection<string> _CodecModes;
_CodecModes= new ObservableCollection<string>();

public ViewModel()
{
        _FreqList.Add("8 kHz");
        _FreqList.Add("11.025 kHz");
        _FreqList.Add("12 kHz");
        _FreqList.Add("14.7 kHz");
        _FreqList.Add("16 kHz");
        _FreqList.Add("22.050 kHz");
        _FreqList.Add("24 kHz");
        _FreqList.Add("29.4 kHz");
        _FreqList.Add("32 kHz");
        _FreqList.Add("44.100 kHz");
        _FreqList.Add("48 kHz");
        _FreqList.Add("88.2 kHz");
        _FreqList.Add("96 kHz");
        _FreqList.Add("undef");

        _CodecModes.Add("None");
        _CodecModes.Add("A Loop");
        _CodecModes.Add("DSP");
        _CodecModes.Add("I2S");            
}

public ObservableCollection<string> FrequencyList
    {
        get { return _FreqList; }
        set
        {
            _FreqList = value;
            OnPropertyChanged("FrequencyList");
        }
    }

    /// <summary>
    /// Selected Frequency List
    /// </summary>
    private string _selectedFrequencyList;
    public string SelectedFrequencyList
    {
        get { return _selectedFrequencyList; }
        set
        {
            _selectedFrequencyList = value;
            int Listvalue = FrequencyList.IndexOf(_selectedFrequencyList);
            int ListFinalVal = Listvalue + 1;
            SelectedFreq(ListFinalVal);
            OnPropertyChanged("SelectedFrequencyList");
        }
    }

    public void SelectedFreq(int Select)
    {            
        int cmd = 0;
        int numBytes = 0;           

        cmd = ((0x8F00 & 0x7F00) | (m_slot & 0xFF));
        sendBuf[numBytes++] = Convert.ToByte(Select - 1);
    }

    public ObservableCollection<string> ModesList
    {
        get { return _CodecModes; }
        set
        {
            _CodecModes = value;
            OnPropertyChanged("ModesList");
        }
    }

    /// <summary>
    /// Selected Modes List
    /// </summary>
    private string _selectedModesList;
    public string SelectedModesList
    {
        get { return _selectedModesList; }
        set
        {
            _selectedModesList = value;
            int Modevalue = ModesList.IndexOf(_selectedModesList);
            int ModeFinalvalue = Modevalue + 1;
            SelectedMode(ModeFinalvalue);
            OnPropertyChanged("SelectedModesList");
        }
    }

    public void SelectedMode(int Select)
    {
        int cmd = 0;
        int numBytes = 0;           

        cmd = ((0x8F00 & 0x7F00) | (m_slot & 0xFF));
        sendBuf[numBytes++] = Convert.ToByte(Select - 1);
    }

Even though I have set SelectedIndex=1 in my xaml. When I run the app, the combobox has set of items but doesn’t display the selected-index. Am I missing something here???

  • 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-13T02:51:01+00:00Added an answer on June 13, 2026 at 2:51 am

    Setting SelectedIndex=1 conflicts withyour binding if SelectedItem with initial null value.

    You can chnage the binding mode for SelectedItem to OneWayToSource so that the value in the view model won’t be used for setting the selected item:

    <ComboBox Grid.Column="0" ItemsSource="{Binding FrequencyList}" SelectedItem="{Binding SelectedFrequencyList, Mode=OneWayToSource}" SelectedIndex="1" Name="comboBox1" />
    

    Alternatively you can initialize SelectedFrequencyList in view model to the desired frequency:

    public ViewModel()
    {
        _FreqList.Add("8 kHz");
        _FreqList.Add("11.025 kHz");
        _FreqList.Add("12 kHz");
        _FreqList.Add("14.7 kHz");
        _FreqList.Add("16 kHz");
        _FreqList.Add("22.050 kHz");
        _FreqList.Add("24 kHz");
        _FreqList.Add("29.4 kHz");
        _FreqList.Add("32 kHz");
        _FreqList.Add("44.100 kHz");
        _FreqList.Add("48 kHz");
        _FreqList.Add("88.2 kHz");
        _FreqList.Add("96 kHz");
        _FreqList.Add("undef");
    
        SelectedFrequencyList = _FreqList[1];
    }
    

    In this case you don’t need to set the selected index for the combo box at all:

    <ComboBox Grid.Column="0" ItemsSource="{Binding FrequencyList}" SelectedItem="{Binding SelectedFrequencyList, Mode=TwoWay}" Name="comboBox1" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a WPF/XAML app using MVVM and have a collection of strings
I've got style resources in WPF working so that in my App.xaml I can
I am working in WPF and I need to set the Text and ToolTip
I am working on a textbox and combobox in my wpf app. I am
I am working on an app named E-Diary in WPF. Now I have to
We have a working WPF app that we are looking into running in the
I'm working on a wpf c# app and I have a question. I have
I have a wpf app with a regular combobox. When testing this app in
I'm having some trouble getting this to work in a WPF app I'm working
I'm working with a WPF/C# app where I need to lock out users from

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.