Search

Silverlight Combobox Binding Drops after NULL Binding by MCoull1

Closed
as Fixed Help for as Fixed

19
0
Sign in
to vote
Type: Bug
ID: 597689
Opened: 9/14/2010 1:53:31 AM
Access Restriction: Public
2
Workaround(s)
13
User(s) can reproduce this bug
I have a combo box which is bound via its selected value to the foreign key of an entity framework entity. As the parent entity is changed the binding continues to work correctly until the foreign key is null then the combo 'drops' its binding completely.

    <ComboBox Name="cboTitle" DisplayMemberPath="sName" SelectedValue="{Binding eTitleREF, Mode=TwoWay}" SelectedValuePath="ID" Height="21" Width="100">
                                </ComboBox>
Details (expand)

Visual Studio/Silverlight/Tooling version

Silverlight 4

What category (if any) best represents this feedback?

Reliability

Steps to reproduce

Using the entity framework, set the itemsource of datagrid to collection of objects.

Put a grid on the table and set the datacontext of the grid on the selection changed of the datagrid (dgIndividual)

private void dgIndividual_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (dgIndividual.SelectedItem != null)
{
LocalService.IndividualEntity Individual = (LocalService.IndividualEntity)dgIndividual.SelectedItem;

PersonGrid.DataContext = Individual;

}
}

In your list make sure the entities you are bringing back have a combination foreign keys where some are null.

Bind a combo to the foreign key (ID) not the item.


<ComboBox Name="cboTitle" DisplayMemberPath="sName" SelectedValue="{Binding eTitleREF, Mode=TwoWay}" SelectedValuePath="ID" Height="21" Width="100">
</ComboBox>


When you select different items in the grid, after selecting a null valued foreign key the combo will lose it's binding.

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

Combobox loses binding

Expected results

coombobox keeps binding
File Attachments
0 attachments
Sign in to post a comment.
Posted by Stefan U7 on 12/5/2011 at 12:05 AM
hi and no
the problem is not when or that the ItemsSource changes
the problem is that there is no SelectedValue == null item in the ItemsSource list of objects and as soon as the property bound to the SelectedValue (TwoWay) is set to null the SelectedValue binding seems to go byebye.
scenario: you have an ObservableCollection<JOB> bound to ItemsSource (TwoWay) with SelectedValuePath = JOB_ID and DisplayMemberPath = TITLE. SelectedValue is bound to your data object lets say EMPLOYEE.JOB_ID (TwoWay)
the ObservableCollection<JOB> is populated from db (using RIA...) by default the collection will not contain an object of JOB where JOB_ID is null.

my fix is to add such a new JOB() { JOB_ID = null, TITLE = "" } clientside to the collection at the moment...
this should not be by Design because it is not like that in WPF (if i remember correct) nor in WinForms imo

best regards
Posted by Microsoft on 8/4/2011 at 3:06 PM
Seth, the SelectedValue being set to null when the ItemsSource changes is by Design. If you're using a OneWay Binding then the Binding would be detached when this happens. However, if you use a TwoWay Binding, it will not be detached
Posted by robalexclark on 7/21/2011 at 12:28 PM
Hi Microsoft,
I note that the last comment from you was last year and there has been no proper resolution of this issue. Please can you give us an update? - I would say that this is a fairly serious bug that a significant proportion of LOB Siverlight developers will have encountered and deserves an interim patch
Posted by Seth Dingwell on 6/29/2011 at 5:35 AM
This bug is marked as fixed but there are no details on when or how that fix will be available. Is there a patch? Is it just going to be fixed in Silvelight 5?
Posted by Seth Dingwell on 2/24/2011 at 1:50 PM
Is there any update on this bug?

I have found that my bindings will work the first time I load them, but if I then update the bound ItemSource propery, the selectedvalue of the combo box is set to null, even though if the item does exist in the new source collection. As soon as that happens, the bindings are lost and even if I update the bound selected value property, it will not select the item in the combo box. The net effect of that problem is that I cannot load my data more than once for the lifetime of the combo box. This makes the combo box almost useless.
Posted by cmeyer1984 on 2/21/2011 at 4:08 PM
When do you plan to fix this bug?
Posted by Microsoft on 9/14/2010 at 2:11 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Sign in to post a workaround.
Posted by cmeyer1984 on 2/21/2011 at 4:10 PM
There is a workaround regarding this problem: http://forums.lhotka.net/forums/p/9786/46097.aspx. For me it's working pretty well, but it still would be nice to get an official bug fix from Microsoft.
Posted by Seth Dingwell on 5/27/2011 at 10:41 AM
I came up with another workaround for this issue which has been working well for us.

Essentially we just cache the bindings of all the comboxes on a page and re-apply them if the selected value is being set to null.

It is documented here:

http://www.codeproject.com/KB/silverlight/silverlighnullbindingsbug.aspx