views:

21

answers:

0

I use an ObservableCollection<customclass> with an isSelected property bound to a listview. The customclass items are added via asyncrhonous communication with a server. I register to an NotifyCollectionChanged event and there under certain conditions set the isSelected property to true. However, this doesn't update my view. Only after selecting another item does the view get updated. Any idea how this is possible?

Also, items that are not visible only get added to the selectedItems list after they have been scrolled into view. Can this be changed?

<ListBox SelectionMode="Multiple" Style="{StaticResource listBoxStyle}" Margin="12,42,12,43" 
     Name="listConfigurations" ItemsSource="{Binding CustomClass.observablecollection1}" 
     VirtualizingStackPanel.IsVirtualizing="False">
<ListBox.ItemContainerStyle>
    <Style TargetType="{x:Type ListBoxItem}">
        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
    </Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
    <DataTemplate>
        <TextBlock Cursor="Hand" Margin="3" Text="{Binding name}"/>
    </DataTemplate>
</ListBox.ItemTemplate>

The CustomClass has one observable list:

public class CustomClass : AbstractClass
{
public ObservableCollection<AnotherCustomClass> observablecollection1 { get; set; }

public CustomClass() : base()
{
    this.observablecollection1 = new ObservableCollection<AnotherCustomClass>();
}

public override void http_DownloadStringCompletedEventHandler(object sender, DownloadStringCompletedEventArgs e)
{
    if (e.Error == null)
    {
        Collection<AnotherCustomClass> collection = new Collection<AnotherCustomClass>();
        //Use JSON parser to put the e.Result into the collection, this works
        collection = (ObservableCollection<AnotherCustomClass>)parseJSON(e.Result)
        foreach (AnotherCustomClass collectionObject in collection)
        {
            collectionObject.IsSelected = customSettings.Default.savedList.Contains(collectionObject.name);
        }
    }
}
}