I am using Prism 7 and MVVM with the TileViewControl. My viewmodel, which contains an ObservableCollection, is derived from BindableBase, not INotifyCollectionChanged.
My TileViewControl is correctly populated with my initial items in the Observable collection, but does not update when I add an item through a command. The only way I see the new item is if I force a refresh by changing the window size.
My ViewModel has the following definition for the collection:
public class GridTileViewModel : BindableBase, INavigationAware
{
private ObservableCollection<ProfileInformation> _profiles;
public ObservableCollection<ProfileInformation> Profiles
{
get
{
return _profiles;
}
set
{
SetProperty(ref _profiles, value);
}
}
...
}
The command to add the new item is as follows:
private void CopyProfile()
{
if (_selectedProfile != null)
{
MessageBox.Show(String.Format("Copy profile button for Profile {0}.", _selectedProfile.ProfileName),
"Testing", MessageBoxButton.OK, MessageBoxImage.Information);
Profiles.Add(new ProfileInformation("Copy of " + _selectedProfile.ProfileName,
_selectedProfile.ProfileDescription,
!(_selectedProfile.CopyActionViewState != Visibility.Collapsed) ));
// Shouldn't have to do this and it doesn't fix the problem anyway
this.RaisePropertyChanged("Profiles");
}
}
The data context
My TileViewControl is in a usercontrol that I am placing into a Prism region, and uses a custom item style. I based this from the TileViewControl Data Binding sample, and modified the style template to what I wanted the tile to look like.
<syncfusion:TileViewControl x:Name="TilesGrid"
Grid.Row="1"
Margin="10, 0, 10, 10"
ItemsSource="{Binding Profiles, Mode=TwoWay}"
ItemContainerStyle="{StaticResource tileitemstyle}"
MinimizedItemsPercentage="0"
ClipToBounds="True"
IsVirtualizing="True"
VerticalScrollBarVisibility="Visible"
ColumnCount="4" RowCount="3"
SelectedItem="{Binding SelectedProfile}">
<syncfusion:TileViewControl.ItemTemplate>
<DataTemplate>
<local:ProfileTileView/>
</DataTemplate>
</syncfusion:TileViewControl.ItemTemplate>
</syncfusion:TileViewControl>
Why is the TileViewControl not updating when I add items to my ObservableCollection? I have a sample using the same control with code-behind and it works; but I don't want to use code behind; I need MVVM & Prism.
Thanks.