Silverlight combobox selecteditem not updating

07-Jan-2020 23:24 by 5 Comments

Silverlight combobox selecteditem not updating - problems with adult children and dating

Let’s structure our project as below: Let us start playing with the code.First create the Model “Country” having two properties “Display Text” and “Code Name”.

However, in some cases the is not accessible: it happens for elements that are not part of the visual or logical tree.

That means I will be using a Behavior to implement every one of these features. Now, this is not simple code and uses some binding tricks and a little reflection, so I am going to simply paste the code and explain some of the tricks I used.

The first thing I needed to solve was gaining access to the Items Source of the Associated Object.

One of my reader “Girish” recently contacted me with a problem statement. If the Country name is not listed there, the user will chose “Others” from the dropdown menu.

His problem is, he wants to show a Text Box on selection of “Others” from a Combo Box and I informed him to use a Value Converter and also told him, I will do a blog post on it, so that he can understand each step from that. May be, some other people who are new to Silverlight can get benefit from it. On selection of “Others”, it will show a Text Box below the Combo Box where he can enter the desired Country name.

My job as a Product Manager for Infragistics Net Advantage for WPF and Silverlight has many aspects.

One of those aspects is knowing the good and the bad about my product.

Display Text will return the Country name and the Code Name will return the code name of the Country. Here is the code: As mentioned earlier, we are going to return some hard coded Country names for our sample application.

Create a Static class called “Country Service” and call the Get List() method to return a collection of Countries. In the view, we need to include the xmlns namespace for the View Model and the Converter. This step will set the Code Name as value of each combo box item, so that, we will be able to get the Selected Value of the dropdown to do our business logic. Now run your application and you will see the dropdown in the screen.

Here is the code of that: We need the Value Converter, which will be able to convert the Country Code Name to Visibility. Collapsed but when the Code Name is “Others” or something like that (depends on your actual code) return Visibility. Create the Static Resource of Main View Model and Country Code To Visibility Converter, as shown below and set the Data Context of the Layout Root Grid to the Main View Model. After this, set the Binding of the Text Box visibility. Change the value to any country, you will see that there are no Text Box visible in the screen.

As shown in the above screenshot, set the Items Source of the Combo Box to Countries, which is available in your View Model as a Property. It should bind the Selected Value of the Combo Box as the Visibility with the Conversion logic written in the Country Code To Visibility Converter. But once you change it to “Others”, the Text Box will be visible in the screen, where you will be able to enter the new Country. If you now change the Combo selection to any other Country, voila, the Text Box will disappear from the screen.

This is the simplest example I can find of how to do it: stackoverflow.com/questions/1506810/….