This is a migrated thread and some comments may be shown as answers.

RadDataBoundListBox not updated when ItemSource changes or replaced

1 Answer 208 Views
DataBoundListBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stefan
Top achievements
Rank 1
Stefan asked on 06 Dec 2013, 04:43 PM
Hi,

I have a problem using the the RadDataBoundListBox. Its ItemSource is set to an ObservableCollection but the ListBox is not updated automatically when the Collection is changed or completely replaced:

<DataTemplate x:Key="GridItemTemplate">
    <Border Background="#365F70" Width="128" Height="128" Margin="24,0,0,24">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="80"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
 
            <ContentControl Template="{Binding Template}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="-15,0,0,0">
                <ContentControl.RenderTransform>
                    <CompositeTransform ScaleX="1.5" ScaleY="1.5"/>
                </ContentControl.RenderTransform>
            </ContentControl>
            <TextBlock Text="{Binding Name}" FontSize="20" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </Grid>
    </Border>
</DataTemplate>
 
<DataTemplate x:Key="ListItemTemplate">
    <Border Background="#365F70" Height="72" Margin="24,0,24,12">
        <StackPanel Orientation="Horizontal">
            <ContentControl Margin="10,-15,35,0" Template="{Binding Template}" VerticalAlignment="Center">
                <ContentControl.RenderTransform>
                    <CompositeTransform ScaleX="1.5" ScaleY="1.5"/>
                </ContentControl.RenderTransform>
            </ContentControl>
            <TextBlock Text="{Binding Name}" FontSize="20" VerticalAlignment="Center"/>
        </StackPanel>
    </Border>
</DataTemplate>

<telerikPrimitives:RadDataBoundListBox
                        x:Name="RadListBox"
                        ItemTemplate="{StaticResource GridItemTemplate}"
                        ItemTap="RadListBox_OnItemTap"
                        ItemReorderStateChanged="RadListBox_ItemReorderStateChanged"/>

ObservableCollection<Data> dataList;
        private void UpdateDataList() {
            if (dataList == null) {
                dataList= new ObservableCollection<Data>();
                RadListBox.ItemsSource = dataList;
            } else {
                dataList.Clear();
            }
 
            for (int i = 0; i < DataSource.Count; i++) {
                Data data = DataSource[i];
                dataList.Add(data);
            }
             
            RadListBox.UpdateLayout();
        }
private void ToggleClick(object sender, EventArgs e) {
    if (listShown) {
        RadListBox.ItemTemplate = (DataTemplate)Resources["GridItemTemplate"];
        RadListBox.VirtualizationStrategyDefinition = new WrapVirtualizationStrategyDefinition { Orientation = System.Windows.Controls.Orientation.Horizontal };
        RadListBox.IsItemReorderEnabled = false;
    } else {
        RadListBox.ItemTemplate = (DataTemplate)Resources["ListItemTemplate"];
        RadListBox.VirtualizationStrategyDefinition = new StackVirtualizationStrategyDefinition { Orientation = System.Windows.Controls.Orientation.Vertical };
        RadListBox.IsItemReorderEnabled = true;
    }
}

Whenever the UpdateList() Methode is called nothing happens - new items are not shown, deleted items are still visible, etc. Only when using the Toogle function to switch between Grid and List Layout the ListBox is Updated and all Items are shown correctly.

Setting RadListBox.ItemSource to a complete new instance of ObservableCollection instead of Cleaning and re-filling the existing one does not work either.

UPDATE:
I have to correct myselfe. The Update works properly when the List Layout is used but not in Grid mode.

1 Answer, 1 is accepted

Sort by
0
Stefan
Top achievements
Rank 1
answered on 07 Dec 2013, 06:51 AM
OK, I found the source of the problem. When the datalist is refreshed it is filled up with the same objects as before. If these objects do not implement notification on property changes the listBox does not update its view, no matter if the objects are re-inserted or not. Implementing INotifyPropertyChanged on these objects solved the problem.

I was aware that the list needs notification of property changes to update automaticially but I thought the list would update anyway if the objects are removed and re-inserted.
Tags
DataBoundListBox
Asked by
Stefan
Top achievements
Rank 1
Answers by
Stefan
Top achievements
Rank 1
Share this question
or