|
…
<listView:SfListView ItemsSource="{Binding Photos}"
Padding="15,0,15,15"
ItemSize="150"
x:Name="listView"
ItemSpacing="4"
IsScrollBarVisible="False"
SelectionBackgroundColor="Transparent"
TapCommand="{Binding ImageTapCommand}">
<listView:SfListView.DataSource>
<data:DataSource>
</data:DataSource>
</listView:SfListView.DataSource>
<listView:SfListView.GroupHeaderTemplate>
<DataTemplate>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Key,StringFormat='{0:MMMM dd, yyyy}'}"
FontFamily="{StaticResource Montserrat-SemiBold}"
FontSize="12"
Margin="0,5,0,0"
LineHeight="{OnPlatform Android=1.25,
Default=-1}"
TextColor="{DynamicResource Gray-800}"
VerticalOptions="Center"
HorizontalOptions="StartAndExpand"/>
</StackLayout>
</DataTemplate>
</listView:SfListView.GroupHeaderTemplate>
<listView:SfListView.ItemTemplate>
<DataTemplate>
<Grid BackgroundColor="{DynamicResource Gray-200}">
<Image Aspect="AspectFill"
BackgroundColor="{DynamicResource Gray-200}"
HeightRequest="150"
WidthRequest="150">
<Image.Source>
<UriImageSource Uri="{Binding ImageURL}"
CacheValidity="14"
CachingEnabled="true"/>
</Image.Source>
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={x:Reference listView}, Path=BindingContext.ImageTapCommand}" CommandParameter="{Binding ImageURL}"/>
</Image.GestureRecognizers>
</Image>
</Grid>
</DataTemplate>
</listView:SfListView.ItemTemplate>
<listView:SfListView.LayoutManager>
<listView:GridLayout SpanCount="{core:OnPlatformOrientationIntValue PhonePortrait=2,PhoneLandscape=5,TabletPortrait=6,TabletLandscape=10,Desktop=10}"/>
</listView:SfListView.LayoutManager>
</listView:SfListView>
</StackLayout> |
|
public class PhotosViewModel : BaseViewModel
{
#region Fields
private Command editCommand;
private Command imageTapCommand;
..
/// <summary>
/// Gets the image tap command
/// </summary>
public Command ImageTapCommand
{
get
{
return this.imageTapCommand ?? (this.imageTapCommand = new Command(this.OnImageTapped));
}
}
..
/// <summary>
/// Invoked when the album image is clicked
/// </summary>
/// <param name="obj">The Object</param>
private void OnImageTapped(object obj)
{
App.Current.MainPage.Navigation.PushAsync(new ContentPage()
{
Content = new StackLayout()
{
Children =
{
new Image()
{
Source = ImageSource.FromUri(new System.Uri(obj.ToString())),
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
}
}
}
});
}
..
} |
|
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={x:Reference listView}, Path=BindingContext.ImageTapCommand}" CommandParameter="{Binding .}"/>
</Image.GestureRecognizers> |
|
private void OnImageTapped(object obj)
{
var photo = obj as Photo;
App.Current.MainPage.Navigation.PushAsync(new ContentPage()
{
Content = new StackLayout()
{
Children =
{
new Label() {Text = photo.Date.ToString()},
new Image()
{
Source = ImageSource.FromUri(new System.Uri(photo.ImageURL.ToString())),
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
}
}
}
});
} |