Skip to main content

Microsoft Silverlight

Answered Question Binding a Combobox in a user controlRSS Feed

(0)

Savij
Savij

Member

Member

1 points

7 Posts

Binding a Combobox in a user control

Hello,

I am trying to create a user control that contains a combobox and 2 textblocks. I want to expose binding points in xaml so I can bind the text properties on the textblocks and also bind the combo box. Again I want to do all of my binding in xaml rather than in code.

I am only working on the combobox binding right now, once I get that working, the text properties should be easy enough.

Here is what I am thinking (but it's not working):

My user control xaml looks like this:
<sydControls:CascadingPicker TitleText="Select Year" FooterText="Hover To Change" Margin="8,241,513,94" ComboDataContext="{Binding Source={StaticResource YearDataSource}}" ComboItemsSource="{Binding Mode=OneWay}" ComboItemTemplate="{StaticResource YearsComboItem}" />

I have properties for ComboDataContext, ComboItemSource and ComboItemTemplate and they all set and get the actual combobox properties of the same name (without the "Combo"). For example: public IEnumerable ComboItemsSource
{
   get { return _cboData.ItemsSource; }
   set { _cboData.ItemsSource = value; }
}

Everything builds fine, but running the page gives me:
""AG_E_PARSER_BAD_PROPERTY_VALUE [Line: 180 Position: 131]"

Which points to "ComboDataContext" .... I am baffled on this one. Can anyone point me in the right direction?

 

Thanks!

-Savij

 

RogerGu
RogerGu

Participant

Participant

870 points

255 Posts

Re: Binding a Combobox in a user control

I would first try to make the error go away before you make it funciton properly. If you you remove the ComboDataContext, does it run without error? And it seems you have the two reversed. Wouldn't you give the ComboItemSource the YearDataSource?

Savij
Savij

Member

Member

1 points

7 Posts

Re: Binding a Combobox in a user control

 If I remove the properties that set the bindings, then yes it compiles and runs, but of course, the combo is empty. So that doesnt really get me anywhere. As far as the two being reversed, I copied the 3 properties (DataContext, ItemsSource and ItemTemplate) from a working combobox on the same page, then I just added the word "Combo" in front of the 3 property names and made sure they matched properties on the code behind. The original post is the result.

I played with the code last night for a while longer, but I am unable to get it to populate the combobox.

 

-Savij

Savij
Savij

Member

Member

1 points

7 Posts

Answered Question

Re: Binding a Combobox in a user control

I found my answer and wrote a blog article about it. With how common this would be in a production application and the fact that I was not able to get much help on the subject, I wonder how many people are just playing with the technology and how many really use Silverlight for production applications?? I think it will get better over time (use and support).

Anyway, here is the article, hope it helps someone out there. Let me know with a comment on the blog if you find it useful (or if anything is incorrect of course).

Savij.com

Enjoy!

-Savij
www.savij.com

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities