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

  • Home
  • SEARCH
  • 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 8325817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:33:53+00:00 2026-06-09T00:33:53+00:00

I have a ComboBox whose XAML looks as follows: <StackPanel Grid.Row = 0 Style={DynamicResource

  • 0

I have a ComboBox whose XAML looks as follows:

  <StackPanel Grid.Row = "0" Style="{DynamicResource chartStackPanel}">
        <Label    Content="Port:" HorizontalAlignment="Left" Margin="8,0,0,0"/>
        <ComboBox Width="75" Height="24" HorizontalAlignment="Right" Margin="8,0,0,0" SelectedValue="{Binding Port, Mode=OneWayToSource}">
            <ComboBoxItem Content="C43"/>
            <ComboBoxItem Content="C46" IsSelected="True"/>
            <ComboBoxItem Content="C47"/>
            <ComboBoxItem Content="C48"/>
        </ComboBox>
    </StackPanel>

The style referenced above is defined as follows:

When the ComboBox is first displayed, I’d like the ‘C46’ item displayed in the ComboBox. However, when this loads, the ComboBox is blank. What’s interesting is that the source property, in my VM, is getting set to ‘C46’. Can anyone tell what I’m doing wrong?

  • 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-09T00:33:55+00:00Added an answer on June 9, 2026 at 12:33 am

    You mention that you have a source collection in your ViewModel. Therefore, why do you specify ComboBoxItems one by one in XAML? I think you should have in your ViewModel a Collection of Items property and also SelectedItem property. In the constructor you can set the SelectedItem. It can looks as follows:

    public ObservableCollection<MyClass> Items { get;set; }
    
    public MyClass SelectedItem
    {
      get {return this.selectedItem;}
      set {
           this.selectedItem = value;
           RaisePropertyChanged("SelectedItem");
          }
    }
    

    And in your constructor after Items property is initialized:

    this.SelectedItem = Items[x]
    

    Your XAML can looks as follows then:

    <ComboBox Width="75" Height="24" HorizontalAlignment="Right" Margin="8,0,0,0" 
                          ItemsSource="{Binding Items}"
                          SelectedItem="{Binding Path=SelectedItem}"
                          DisplayMemberPath="Content"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ComboBox whose xaml is as follows <ComboBox Name=ComboBoxDiscussionType IsEnabled={Binding ElementName=ComboBoxDiscussionType, Path=Items.Count,
I have a combobox whose value I want to use with a SQL WHERE
I have a ComboBox, whose ItemsSource is bound to a new (not default) ListCollectionView,
I have a combobox in Access 2003 whose recordset is obtained from a stored
Scenario : I have a ContentControl in my View whose Content property is bound
I have a ComboBox with 2 items whose contents are databound to 2 dependency
I have a ComboBox whose ItemsSource is bound to an ObjectDataProvider that has its
I have a ComboBox in WPF whose ItemsSource is set to a list programmatically.
I have a style to a custom control that inherits from combobox that I
i have a combobox whose datasource is a datatable. i need to loop through

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.