0

I've tried to bind IsHitTestVisible of a GridViewItem using MVVM. I've updated the value from "False" to "True" of the particular Model and notified View using INotifyPropertyChanged. But it is not affecting in the view. But if I bind value directly for IsHitTestVisible in the setter, its working fine. Anyone can help on this?

<GridView 
   Grid.Row="1" 
   Name="gvCatalogue" 
   Width="Auto" 
   Height="Auto" 
   HorizontalAlignment="Left" 
   HorizontalContentAlignment="Left" 
   ItemsSource="{Binding Path=Catalogue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
   IsItemClickEnabled="True" >
   <GridView.ItemsPanel>
      <ItemsPanelTemplate>
         <VirtualizingStackPanel Orientation="Horizontal" Margin="0"/>
      </ItemsPanelTemplate>
   </GridView.ItemsPanel>
   <GridView.ItemContainerStyle>
      <Style TargetType="GridViewItem">
         <Setter Property="IsHitTestVisible" Value="{Binding Path=HitTestVisible, Mode=OneWay}"/>
      </Style>
   </GridView.ItemContainerStyle>
   <GridView.ItemTemplate>
      <DataTemplate>
         <Grid Name="ItemGrid" RightTapped="gvItem_RightTapped" Width="230" >
            <Grid.ColumnDefinitions>
               <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <StackPanel Grid.Column="0" VerticalAlignment="Top" Height="260" Width="175" Orientation="Vertical" HorizontalAlignment="Center" >
               <Image Source="{Binding Path=BitmapImage, Mode=OneWay}" Height="250" Width="175" HorizontalAlignment="Center"/>
            </StackPanel>
         </Grid>
      </DataTemplate>
   </GridView.ItemTemplate>
</GridView>

In ViewModel, I'm updating the Model "CatalogItem" like this:

 private async Task DownloadFile(string fileLocation, string FileName, bool IsZip)

 {

        CatalogueItem.HitTestVisible = false;

        CatalogueItem.DownloadingProgress = Visibility.Visible;

        var uri = new Uri(fileLocation);

        var downloader = new BackgroundDownloader();

        StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting);

        DownloadOperation download = downloader.CreateDownload(uri, file);

        var progress = new Progress<DownloadOperation>(ProgressCallback);

        await download.StartAsync().AsTask(progress);    

        CatalogueItem.HitTestVisible = true;


    }
Filip Skakun
  • 31,624
  • 6
  • 74
  • 100

1 Answers1

0

Last time I checked bindings did not work in style setters in WinRT/XAML. I mentioned a workaround in the answer to this question:

How do I do bindings in ItemContainerStyle in WinRT?

Community
  • 1
  • 1
Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
  • Thanks for your finding. Can you help me with another way of workaround solution. How can we avoid IsHitTestVisible value from a Parent element. I mean... asper your comment, I removed the binding from style setters and then added inside the Grid - "ItemGrid". Now binding is working. But the IsHitTestVisible of Parent - GridView is affecting it. How to avoid this scenario? – Supratheesh Surendran Jun 27 '14 at 07:04
  • Hey @Filip, I mean I want a GridView with ItemTemplate "Grid". But I should be able to click one which is downloaded already and another one not able to click as its being downloaded. Please help – Supratheesh Surendran Jun 27 '14 at 07:23
  • You can use an attached behavior that configures your binding in code or you can subclass `GridView` and override [`PrepareContainerForItemOverride`](http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.itemscontrol.preparecontainerforitemoverride.aspx) where you'd bind `IsEnabled` of the container element (`GridViewItem`) to the item (your item view model). – Filip Skakun Jun 27 '14 at 14:30