Silverlight - ComboBox
March 27, 2008 by lee
Here is sample implementation of ComboBox in silverlight. it has the basic functionality. Ideally a Popup Control should be used in the controltemplate of the combobox. For some reason, it was not working when ItemsPresenter is added to Popup, will look into it
you can download the source here
Hi Lee,
were you able to figure out the popup thing?
thanks.
p.s. thanks for sharing.. great way to learn looking at your code.
No, I did not get back to that. I might take another look when Beta 2 is released
If your ComboBox is built in a Silverlight Library Application and then I use it as a control in a Siverlight Application it doesn’t work.
Can you help me this problem?
Thanks! GoodLuck to you!
Thao Nguyen
sure, are you getting error or combobox is not showing up
Now, SL Beta 2 is released. When you create a new version of Combobox control. I have to complete my thesis, but if I change to SL beta 2 I don’t have combobox to use. Thanks! Hope here from you soon.
I am getting exception, when I tried to convert. It doesnt give me any more details/line numbers other than the following
System.CrossAppDomainMarshaledException was unhandled
Message: System.NullReferenceException: Object reference not set to an instance of an object.
at MS.Internal.Error.GetXresultForException(Exception ex)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
I will post in the forum and see if someone will help me figure out what is going on
As soon as I figure out what is going on, I will upload again
Note: I am not sure when the final version of Silverlight is going to be released. but it will have a ComboBox natively from Microsoft
I looked at it a bit and it looks like they changed the base template on you. In OnApplyTemplate you are looking for objects that aren’t found:
as Button;
as ContentPresenter;
_dropDownButton = GetTemplateChild(”ButtonElement”
_cp = GetTemplateChild(”ContentSite”
_border = GetTemplateChild(”border”
as Border;
These all return null. And ugliness follows..
-Gary
I closed and opened the project and Isaw the same error. I dont have a clue. may be I will write a blog post also while waiting for an answer in the forums
hello! Trying to make it work with SL2B2.
I get error on each
new PropertyChangedCallback(OnIsSelectedChanged))
I tried to change it to new PropertyMetaData(OnIsSelectedChanged)), compiles but it crashes… any idea?
look at this post, I am trying to convert but facing issues
http://leeontech.wordpress.com/2008/06/09/gettemplatechild-issue-slbeta2/
have to make the changes I mentioned in the update, but still have issues
i will post an update, If I figure out the issue
I updated the code to work in beta 2, you can find the code at http://leeontech.wordpress.com/2008/06/11/combobox-code-updated-to-beta2/