Issue when Declaring a ComboBox Object using C# code
NickName:boring91 Ask DateTime:2013-03-15T20:41:54

Issue when Declaring a ComboBox Object using C# code

I'm making a program for window phone using silverlight.

I have a small problem and it is about creating a combo box.

I can create it using xaml, but I am in a situation where I should declare it using c# code.

The problem is after creating a new instance of the combo box and adding the items to it, the combo box doesn't appear!!

The code:

        TextBlock tb = new TextBlock();
        tb.Text = "Select your arrival status";

        tb.Margin = new Thickness(5.0);
        tb.FontSize = 20;
        tb.Foreground = new SolidColorBrush(Colors.White);

        ComboBox cb = new ComboBox();
        ObservableCollection<string> testList = new ObservableCollection<string>();
        testList.Add("Hi");
        testList.Add("Hi1");
        testList.Add("Hi2");
        cb.DataContext = testList;
        cb.Height = 50;
        cb.Width = 200;
        cb.Foreground = new SolidColorBrush(Colors.White);

        panel.Children.Add(tb);
        panel.Children.Add(cb);

As you can see from the code, I have declared a TextBlock and a Combobox objects. The TextBox object appears whereas the the Combobox doesn't.

Any help will be appreciated.

Copyright Notice:Content Author:「boring91」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15432788/issue-when-declaring-a-combobox-object-using-c-sharp-code

More about “Issue when Declaring a ComboBox Object using C# code” related questions

Issue when Declaring a ComboBox Object using C# code

I'm making a program for window phone using silverlight. I have a small problem and it is about creating a combo box. I can create it using xaml, but I am in a situation where I should declare it...

Show Detail

A Combobox Population issue

I am using the following function to populate my ComboBox public static void FillDropDownList(string Query, System.Windows.Forms.ComboBox DropDownName, string AValue, string Adisplay) {

Show Detail

Object required with Access Combobox in With statement

this is a separate issue with a previous one that I had submitted and got some help with. I'm trying to work with some code that checks a numeric ID field on a form (Record set originates from a q...

Show Detail

ComboBox doubling in values c#

I have following piece of code: private void nameTextBox_Leave(object sender, EventArgs e) { var names = ConfigurationManager.AppSettings.AllKeys .Whe...

Show Detail

C# WPF - ComboBox highlighting text colour issue

I have an issue with ComboBox highlighting which shows black text on a blue background, when the text for highlighting should be white. I have examples of ComboBox which use ComboBoxItems where the

Show Detail

Populating a combobox with c# using MVVM paradigm

I want to display 'user groups' in a combobox, and bind the selected usergroup key to a variable in my view model. I am using the MVVM paradigm, and I know it is very close to working but i just c...

Show Detail

C# ComboBox GotFocus

I have a C# ComboBox using WPF. I have code that executes when the ComboBox's GotFocus is activated. The issue is that the GotFocus event is executed every time a selection is made from the Combo...

Show Detail

XML and ComboBox in C#

I'm trying to match selected year in ComboBox dropdown list with national holidays in Ireland, so when the user click on, e.g. 2010, he gets the list of holidays along with their corresponding date...

Show Detail

Vuetify Combobox issue when clicking on the edge of another combobox or outside of combobox

I have a simple page that uses vuetify combobxes and vuetify inputs. I have been working on a way to switch focus of the comboboxes when an added item is confirmed to be added to the list. This works

Show Detail

How to workaround C# sorting error in Combobox when AutoCompleteMode is Suggest?

There is a sorting error in C# in Combobox when using AutoCompleteMode with mode Suggest and AutoCompleteSource is ListItems. Example: Combobox contains items: "Svedberg", "Swedbank", "Swedis...

Show Detail