【问题标题】:Xamarin ffimageloading plugin tap to full screenXamarin ffimageloading 插件点击到全屏
【发布时间】:2017-12-07 09:48:57
【问题描述】:

下面的代码使用ffimageloading 组件渲染一个高度为 200px 的图像。我需要点击此图像并全屏显示图像或缩放它。是否可以使用 ffimageloading 或者我需要通过每个平台(android 和 ios)实现它?

查看

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             prism:ViewModelLocator.AutowireViewModel="True"
             xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
             x:Class="Namespace.Views.MyClass">

<Grid Padding="0"
                  Margin="0"
                  BackgroundColor="{StaticResource BackgroundColor}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="200" />
                    </Grid.RowDefinitions>

                    <ffimageloading:CachedImage 
                        Grid.Row="0"
                        Source="{Binding ThumbPath}"
                        Aspect="AspectFill">
                        <ffimageloading:CachedImage.LoadingPlaceholder>
                            <OnPlatform   
                            x:TypeArguments="ImageSource"
                            iOS="logo_header"
                            Android="logo_header" />
                        </ffimageloading:CachedImage.LoadingPlaceholder>
                        <ffimageloading:CachedImage.ErrorPlaceholder>
                            <OnPlatform   
                            x:TypeArguments="ImageSource"
                            iOS="noimage"
                            Android="noimage" />
                        </ffimageloading:CachedImage.ErrorPlaceholder>
                    </ffimageloading:CachedImage>
                </Grid>
</ContentPage>

ViewModel(使用prism

public class MyClassViewModel : BindableBase, INavigationAware
{
   public MyClassViewModel()
   {
   }

    private string _thumbPath;

    public PerfilPetDto ThumbPath
    {
        get
        {
            return "https://www.google.com.br/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png";
        }
        set
        {
            _thumbPath = value;
            RaisePropertyChanged(nameof(ThumbPath));
        }
    }
}

【问题讨论】:

  • 我是否需要为 --> await CoreMethods.PushPageModel(imageName, false); 编写单独的代码?

标签: xamarin.forms ffimageloading


【解决方案1】:

首先要做的是在缓存的图像中添加一个手势识别器

<ffimageloading:CachedImage.GestureRecognizers>
    <TapGestureRecognizer Command="{Binding ViewImageCommand}" />
</ffimageloading:CachedImage.GestureRecognizers>

这使用命令绑定到视图模型中的命令

private Command _viewImageCommand;
public Command ViewImageCommand => _viewImageCommand ?? (_viewImageCommand = new Command(async () => await ViewImage()));

private async Task ViewImage()
{
    await CoreMethods.PushPageModel<FullScreenImagePageModel>(imageName, false);
}

这会推动另一个页面以全屏显示图像。

我正在使用 FreshMvvm 将图像名称传递给全屏图像视图模型。

【讨论】:

  • 好消息。很高兴我能帮上忙。
  • @SteveChadbourne 我需要为 --> await CoreMethods.PushPageModel&lt;FullScreenImagePageModel&gt;(imageName, false); line 编写单独的代码吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-06
  • 1970-01-01
  • 2018-10-22
  • 2014-04-30
相关资源
最近更新 更多