WPF data-bound ComboBox only shows first item of ItemsSource list
Posted
by Mark
on Stack Overflow
See other posts from Stack Overflow
or by Mark
Published on 2010-06-09T02:38:44Z
Indexed on
2010/06/09
2:42 UTC
Read the original article
Hit count: 245
Hi all,
I'm sure I'm doing something stupid but for the life of me I can't think of right now. I have a ComboBox that is data-bound to a list of Layout objects. The list is initially empty but things are added over time.
When the list is updated by the model the first time, this update reflects properly in the ComboBox. However, subsequent updates never show up in the ComboBox even though I can see that the list itself contains these items. Since the first update works, I know the data-binding is OK - so what am I doing wrong here?
Here's the XAML (abridged):
<Grid HorizontalAlignment="Stretch">
<ComboBox ItemsSource="{Binding Path=SavedLayouts, diagnostics:PresentationTraceSources.TraceLevel=High}" DisplayMemberPath="Name" SelectedValuePath="Name" SelectedItem="{Binding LoadLayout}" Height="25" Grid.Row="1" Grid.Column="0"></ComboBox>
</Grid>
And the related part of the model:
public IList<Layout> SavedLayouts { get { return _layouts; } }
public Layout SaveLayout( String data_ )
{
Layout theLayout = new Layout( SaveLayoutName );
_layouts.Add( theLayout );
try
{
return theLayout;
}
finally
{
PropertyChangedEventHandler handler = PropertyChanged;
if( handler != null )
{
handler( this, new PropertyChangedEventArgs( "SavedLayouts" ) );
}
}
}
And finally, the layout class (abridged):
public class Layout
{
public String Name
{
get;
private set;
}
}
In the output window, I can see the update occurring:
System.Windows.Data Warning: 91 : BindingExpression (hash=64564967): Got PropertyChanged event from TickerzModel (hash=43624632)
System.Windows.Data Warning: 97 : BindingExpression (hash=64564967): GetValue at level 0 from TickerzModel (hash=43624632) using RuntimePropertyInfo(SavedLayouts): List`1 (hash=16951421 Count=11)
System.Windows.Data Warning: 76 : BindingExpression (hash=64564967): TransferValue - got raw value List`1 (hash=16951421 Count=11)
System.Windows.Data Warning: 85 : BindingExpression (hash=64564967): TransferValue - using final value List`1 (hash=16951421 Count=11)
But I get do not get this 11th item in the ComboBox.
Any ideas?
© Stack Overflow or respective owner