CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Silverlight 4 ComboBox is broken and wasting my time.

This post has 37 Replies | 16 Followers

Not Ranked
Posts 1

SelectedValue worked in .NET 3.5, but broke when I upgraded to .NET 4.  Your class fixes the problem very nicely.  Thanks so much for posting it!

Top 25 Contributor
Posts 450

Jaans:

Ps: Whisper Hannes, lyk my die boere moet mekaar maar help.

You got me there. At first I thought it was dutch but of course it's afrikaans Smile

Tiago Freitas Leal, CslaGenFork (Open Source CSLA code generator)

Top 10 Contributor
Posts 1,772
JonnyBee replied on Fri, Dec 31 2010 3:32 AM

Hi Jaans,

I'd lik to add the ComboBoxEx class/control to CslaContrib.Xaml.Silverlight project to make it more easily available for Csla developers.

Would you agree to submit the extended control to cslaContrib?

Jonny Bekkum, Norway CslaContrib Coordinator

Top 50 Contributor
Posts 187
Jaans replied on Fri, Dec 31 2010 8:16 PM

Hi Jonny

Sure! No problem... let me know if I can help.

Happy 2011 !!

Top 50 Contributor
Posts 187
Jaans replied on Fri, Dec 31 2010 8:21 PM

Hi all

If you would like to help put pressure on Microsoft to fix the ComboBox for Silverlight, please cast you votes here at user voice:

http://dotnet.uservoice.com/forums/4325/suggestions/1273023

Jaans

Not Ranked
Posts 1
kita replied on Thu, Jan 6 2011 4:11 PM

Hi Jaans,

I am using your cutom combobox and I got this error message

Cannot call StartAt when content generation is in progress.

   at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.StartAt(GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem)
   at System.Windows.Controls.ComboBox.SetContentPresenter(Int32 index)
   at System.Windows.Controls.ComboBox.PrepareContainerForItemOverride(DependencyObject element, Object item)
   at Smac.Controls.CustomComboBox.PrepareContainerForItemOverride(DependencyObject element, Object item)

I have trying to find out what's going on, but I am stuck. Do have any idea about this error message?

Thanks, Kita

Top 50 Contributor
Posts 187
Jaans replied on Thu, Jan 6 2011 5:07 PM

Hi Kita

Unfortunately I haven't seen that particular error message before.

From the error stack it would appear that the PrepareContainerForItemOverride is being called at an inappropriate time. The ComboBox solution at the start of this thread does not override it, so I'm assuming your code does directly (or indirectly) - likely ways that could cause it are:

  • Method overload
  • Style
  • Overriding a different ComboBox class (other that the one from System.Windows.Controls

Check your code and comment out any method overloads for the combobox, styles (explicit or implicit), maybe even temporarily disable themes (if you're using them) just to figure out what the source this error is.

Hope that helps some,
Jaans

Not Ranked
Posts 2
yesso replied on Thu, Feb 10 2011 5:45 AM

hallo, thanks for that implementation.

your combobox works great with selectedvalue but in my case i have two comboboxes. the first is the "master" combobox, the second the "slave" combobox. the slave combobox should populated (itemsource property) dependend on the selected item of master combobox. some master items has no sub items.

when i select one master item which should not has sub items the itemsource of slave combobox is updated, the converter is getting the selected item of master combobox and returning a collection with zero items. but the combobox is not updating correctly, i can see that the slave combox.itemsource.count is zero but the old selected item is shown ! also the selected index is wrong index...

 

any idea how i can fix it?

best regards

Not Ranked
Posts 2
yesso replied on Thu, Feb 10 2011 6:46 AM

i have solved the problem by looking on your old post about the combobox :)

i have changed the code:

        /// <summary>
        /// Sets the selected value suppressing change event processing.
        /// </summary>
        /// <param name="newSelectedValue">The new selected value.</param>
        private void SetSelectedValueSuppressingChangeEventProcessing(object newSelectedValue)
        {
            try
            {
                _suppressSelectionChangedUpdatesRebind = true;
                SelectedValue = newSelectedValue;

                var sel = (from item in this.Items
                           where GetMemberValue(item).Equals(newSelectedValue)
                           select item).SingleOrDefault();

                this.SelectedItem = sel;
               
            }
            finally
            {
                _suppressSelectionChangedUpdatesRebind = false;
            }
        }

 

 

know it works fine...

here my xaml code:

                                     <myctrl:ComboBoxEx x:Name="cmboxSubType"
                                                       DisplayMemberPath="DisplayMember"
                                                       SelectedValuePath="ValueMember"
                                                       SelectedValueProper="{Binding Path=SubType, Mode=TwoWay}"
                                                       ItemsSource="{Binding ElementName=cmboxType, Path=SelectedItem, Converter={StaticResource EnumToComboBoxItemsConverter}, ConverterParameter=SUBTYPE}"
                                                       >                                    
                                    </myctrl:ComboBoxEx>

Not Ranked
Posts 1

You just saved me a lot of time. This bug is so annoying. Your fix worked like a charm.

Thanks!!

 

Not Ranked
Posts 1

Hi there Jaans,

 

Wow, okay I'm a bit of a newbie, but your code has saved me a lot of arsing around. All I wanted to do was to be able to update the text that we can see when the combo box is not in drop down mode. Jesus H Christ was that like trying to pull teeth. I was on the Silverlight forums for days... but this fixes it.

I created an account just so I could tell you how grateful I am for this.

Not Ranked
Posts 1
vvalk replied on Tue, Apr 19 2011 8:34 AM

In my project I replaced the original combobox with the extended one and now binding to nullable foreign keys became easy. But I noticed that if ItemsSource of the combo is bound to ICollectionView, CurrentChanged event of the view doesn't get fired...

To handle this situation I modified the ComboBoxEx_SelectionChanged event handler:

private void ComboBoxEx_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Avoid recursive stack overflow
            if (_suppressSelectionChangedUpdatesRebind)
                return;
 
            if (e.AddedItems != null && e.AddedItems.Count > 0)
            {
                //SelectedValueProper = GetMemberValue( e.AddedItems[0] );
                SelectedValueProper = SelectedValue; // This is faster than GetMemberValue
                                
                if (this.ItemsSource is ICollectionView)
                    (this.ItemsSource as ICollectionView).MoveCurrentTo(this.SelectedItem);
            }
            // Do not apply the value if no items are selected (ie. the else)
            // because that just passes on the null-value bug from the combobox            
        }
Top 50 Contributor
Posts 178
Tim replied on Tue, Aug 2 2011 9:37 PM

I wanted to provide an update on something I found related to Jaans' fix.  While using his solution, I came across an issue in SL4/CSLA 4.1 where I would select a combobox item from the list but the item would not appear as the selected item.  If I selected the same item a second time, it finally appeared as selected.  In addition, binding was not working...it wouldn't save.

I tried Walk's modification, and it seemed to make the selection issue work correctly (i.e. the first selection made the item actually appear as selected), but two-way binding was still not working.  I noticed the other combobox on my usercontrol was working fine with Jaans' code, so I began to look at what was different between the two.  Turns out the problem had something to do with binding to a managed property that was defined as a byte.  I changed this to an int and everything started working fine.

Tim

Not Ranked
Posts 1

I can use this getting selected value is working fine but i need selectionChanged for my own use. i hae functionalities using selectionchanged in my project. And also when i use this im receiving an error

 "Failed to assign to property 'System.Windows.FrameworkElement.Style'. [Line: 279 Position: 240]"

can u help me out...

Not Ranked
Posts 1

A quick solution is, store the selected item in a tempure var, then restore the item from it. Smile

Page 2 of 3 (38 items) < Previous 1 2 3 Next > | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems