2012-05-25 47 views
1

我在listview中顯示一個集合,並且每個listview項目都有自己的用於下載相關pdf的按鈕。Caliburn Micro - 更改BindableCollection中的單個項目

我想單擊按鈕並在它的位置顯示一個不確定的進度條。

在我的示例項目中,我只是試圖在單擊按鈕時反轉項目的下載狀態。

我的視圖模型代碼:

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")); 
} 

我的觀點:

<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> 

我曾想到,NotifyOfPropertyChanged會告訴集合的項目進行更新,但不會出現這種情況。

回答

3

這與收藏無關。模板綁定到項目本身。它不知道收集。這意味着,您需要在項目本身中實施通知(INotifyPropertyChanged)。