简体   繁体   English

Xamarin Xamarin shell 页之间发送64格式图片

[英]Xamarin Send an image in 64 format between Xamarin shell pages

I apologize in advance for my poor spelling due to my reliance on google translate由于我依赖谷歌翻译,我为我的拼写错误提前道歉

When sending an image in 64 format between Xamarin shell pages, the property is not affected in the recipient ViewModel在 Xamarin shell 页面之间发送 64 位格式的图像时,该属性在接收方 ViewModel 中不受影响

Here is the query sending code这是查询发送代码

await Shell.Current.GoToAsync(
    state: $"{nameof(SuppliersByProdectID)}?" +
    $"{nameof(Suppliers.SuppliersByProdectID.ItemId)}={item.AIItemId}" + "&" +
  //
  //Image property is string here
  //
    $"{nameof(Suppliers.SuppliersByProdectID.Image)}={item.AIItemImage}");

Here is the Query receipt code这是查询收据代码

[QueryProperty(nameof(ItemId), nameof(ItemId))]
[QueryProperty(nameof(Image), nameof(Image))]
public class SuppliersByProdectID : MyBaseViewModel
{
    private string image;
    public string Image
    {
        get => image;
        set
        {
            //I set a breakpoint here, but the program does not stop 
            //at it
            SetProperty(ref image, value);
            ItemImage = ImagesConverter.GetImageSource(value);
        }
    }

    private ImageSource itemImage;
    public ImageSource ItemImage
    {
        get => itemImage;
        set => SetProperty(ref itemImage, value);
    }

    private string itemId;
    public string ItemId
    {
        get => itemId;
        set
        {
            SetProperty(ref itemId, value);
            FillSuppliers();
        }
    }
}

Execution does not pass the Image property, although it carries a value in the ViewModel dispatch, and this is when the execution is stopped with a breakpoint执行不传递 Image 属性,尽管它在 ViewModel 调度中带有一个值,这是执行通过断点停止的时候

If you want to transfer string of Image to ViewMode l of navigated page.如果要将 Image 字符串传输到导航页面的ViewMode l。 You can use Process navigation data using a single method to achieve it.您可以使用Process navigation data using a single 方法来实现它。

Navigation data can be received by implementing the IQueryAttributable interface on the ViewModel : SuppliersByProdectID .The following example shows a view model class that implements the IQueryAttributable interface:可以通过在ViewModel上实现IQueryAttributable接口来接收导航数据: SuppliersByProdectID 。以下示例显示了实现 IQueryAttributable 接口的视图 model class:

public class MonkeyDetailViewModel : IQueryAttributable, INotifyPropertyChanged
{
    public Animal Monkey { get; private set; }

    public void ApplyQueryAttributes(IDictionary<string, string> query)
    {
        // The query parameter requires URL decoding.
        string name = HttpUtility.UrlDecode(query["name"]);
        LoadAnimal(name);
    }

    void LoadAnimal(string name)
    {
        try
        {
            Monkey = MonkeyData.Monkeys.FirstOrDefault(a => a.Name == name);
            OnPropertyChanged("Monkey");
        }
        catch (Exception)
        {
            Console.WriteLine("Failed to load animal.");
        }
    }
    ...
}

For more details, you can refer to https://learn.microsoft.com/en-us/xamarin/xamarin.forms/app-fundamentals/shell/navigation#pass-data .更多详细信息,您可以参考https://learn.microsoft.com/en-us/xamarin/xamarin.forms/app-fundamentals/shell/navigation#pass-data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM