Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Why does my bound listbox not update when a new item is added to my collection?

$
0
0

I have a listbox that is bound to an observablecollection that is not getting updated if I add an item to the observable collection through a new form. The list is a list of users invited to a current meeting. If the meeting creator wants to add users a new window is opened and the bound observablecollection is supplied to it via constructor. The new window is basically like an address book where they can add more invitations. The only problem is when the user objects are added to this list they do not show on the original window where my list box is located. I suppose I could use events to add the user at the original window but I want to know why this specifically doesnt work. 

This is the style I am using for the listbox

<Style TargetType="ListBox" x:Key="InvitationListStyle"><Setter Property="ItemTemplate"><Setter.Value><DataTemplate><Border BorderThickness="0,0,0,1"
                                BorderBrush="Gray"
                                Margin="2,1,2,1"
                                Background="Azure"><Grid><Grid.RowDefinitions><RowDefinition/><RowDefinition/></Grid.RowDefinitions><!--1st Row--><Grid><Grid.ColumnDefinitions><ColumnDefinition/><ColumnDefinition/><ColumnDefinition/></Grid.ColumnDefinitions><TextBlock HorizontalAlignment="Left"
                                               VerticalAlignment="Center"
                                               Text="{Binding Path=FirstName}"/><TextBlock Grid.Column="1"
                                               HorizontalAlignment="Left"
                                               VerticalAlignment="Center"
                                               Text="{Binding Path=LastName}"
                                               Margin="3,0,0,0"/><TextBlock Grid.Column="2" 
                                               HorizontalAlignment="Left"
                                               VerticalAlignment="Center"
                                               FontStyle="Italic"
                                               Foreground="Gray"
                                               TextDecorations="Underline"
                                               Text="{Binding Path=Title}"
                                               Margin="3,0,0,0"/></Grid><!--Second Row--><Grid Grid.Row="1"><Grid.ColumnDefinitions><ColumnDefinition/><ColumnDefinition/></Grid.ColumnDefinitions><TextBlock HorizontalAlignment="Left"
                                               VerticalAlignment="Center"
                                               FontWeight="Bold"
                                               Text="{Binding Path=OrganizationName}"/><TextBlock Grid.Column="1" 
                                               HorizontalAlignment="Left"
                                               VerticalAlignment="Center"
                                               Text="{Binding Path=Status}"
                                               FontWeight="Bold"
                                               Foreground="Blue"
                                               Margin="6,0,0,0"/></Grid></Grid></Border></DataTemplate></Setter.Value></Setter></Style>

I bind it by setting the listitemsource to my observable collection.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>