views:

78

answers:

1

Update:

I've included some diagnostics in the SelectedValue property (diagnostics:PresentationTraceSources.TraceLevel=High) and I think I can see the issue, although I do not know how to fix it. The diagnostics show

System.Windows.Data Warning: 76 : BindingExpression (hash=16001149): TransferValue - got raw value '3'
    System.Windows.Data Warning: 80 : BindingExpression (hash=16001149): TransferValue - implicit converter produced '3'
    System.Windows.Data Warning: 85 : BindingExpression (hash=16001149): TransferValue - using final value '3'
    System.Windows.Data Warning: 86 : BindingExpression (hash=16001149): **Update - got raw value <null>**
    System.Windows.Data Warning: 90 : BindingExpression (hash=16001149): **Update - using final value <null>**
    System.Windows.Data Warning: 98 : BindingExpression (hash=16001149): SetValue at level 1 to LookupModelBase (hash=57292143) using ReflectPropertyDescriptor(PK): <null>
    System.Windows.Data Warning: 91 : BindingExpression (hash=16001149): Got ValueChanged event from LookupModelBase (hash=57292143)
    System.Windows.Data Warning: 85 : BindingExpression (hash=40869743): TransferValue - using final value ObservableCollection`1 (hash=64658589 Count=4)

so the SelectedValue is set to null for some reason.

Has anyone overcome this issue?

Thanks

Hi,

Further to my previous post and to make this a bit clearer than my previous ramblings, I think the question is as follows;

Why would a combobox display be set to blank when another property is amended (due to OnPropertyChanged), even though the actual underlying value is not amended? If I amend a field in the same record the combobox shows as empty, but if I navigate away and back again the value returns?

The xaml is as follows;

            ItemsSource="{Binding TrialParentValues, Mode=OneWay}"
            SelectedItem="{Binding TrialParentObj, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, Mode=TwoWay}"                             
            DisplayMemberPath="Description"             
            SelectedValuePath="PK"
            SelectedValue="{Binding TrialParentObj.PK}"  

Thanks

A: 

Use either a Binding on SelectedValue in combination with SelectedValuePath or a Binding on SelectedItem

Do not use both on your combobox!

In your case, I suggest you remove the SelectedItem binding.

Arcturus
I initially tried that but couldn't get the binding to update at all. I followed this advice http://stackoverflow.com/questions/247413/wpf-combobox-selectedvalue-not-updating-from-binding-source and have had more success but still the above issue.
pilsdumps
The selected value binding breaks when you ItemsSource changes. Thats a nasty issue. Please do try to keep your ItemsSource as a resource or make sure its not dynamic. If it is dynamic, consider a CollectionViewSource.
Arcturus
Ok, thanks for the pointer. What really confuses me is that I've managed to get this to work successfully for other properties, where changing the ItemsSource property doesn't break the binding. However despite a number of hours of searching, I can't seem to work out why it doesn't work in the case I've outlined.
pilsdumps
Its a combination of SelectedValue/Item and the ItemsSource. We've seen it many times in our project. Its the only combination I know of. Refreshing the ItemsSource leads to breaking the SelectedValue binding.
Arcturus