Reputation: 146
I am displaying a collection in a listview, and each listview item has its own button for downloading the related pdf.
I want to click the button and display an indeterminate progress bar in it's place.
In my sample project, I'm merely trying to invert the item's download status when I click its button.
My viewmodel code:
private BindableCollection<IDownloadable> _downloadables;
public BindableCollection<IDownloadable> Downloadables
{
get { return _downloadables; }
set
{
_downloadables = value;
NotifyOfPropertyChange(() => Downloadables);
}
}
public void Download(IDownloadable item)
{
item.Downloading = !item.Downloading;
NotifyOfPropertyChange(() => Downloadables);
}
public ShellViewModel()
{
Downloadables = new BindableCollection<IDownloadable>();
Downloadables.Add(new DownloadString("String"));
Downloadables.Add(new DownloadString("String"));
Downloadables.Add(new DownloadString("String"));
}
My view:
<ListView Name="Downloadables"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid Background="White">
<ToggleButton Content="{Binding MyString}"
Width="50"
Height="50"
HorizontalAlignment="Center"
VerticalAlignment="Center"
cal:Message.Attach="Download($dataContext)"/>
<spark:SprocketControl Width="30"
Height="30"
HorizontalAlignment="Center"
VerticalAlignment="Center"
AlphaTicksPercentage="50"
Interval="60"
IsIndeterminate="True"
LowestAlpha="50"
StartAngle="-90"
TickColor="LawnGreen"
TickCount="12"
TickWidth="3"
Visibility="{Binding Downloading, Converter={StaticResource BooleanToVisibilityConverter}}"/>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
I had imagined that NotifyOfPropertyChanged would tell the collection items to update, but that doesn't appear to be the case.
Upvotes: 2
Views: 2339
Reputation: 12849
This has has nothing to do with collection. The template binds to the item itself. It has no idea about the collection. This means, you need to implement notification (INotifyPropertyChanged) in the item itself.
Upvotes: 5