Xamarin在Xamarin shell页面之间发送64格式的图像

t30tvxxf  于 2023-02-05  发布在  Shell
关注(0)|答案(1)|浏览(141)

我为我的拼写错误提前道歉,由于我对谷歌翻译的依赖
在Xamarin shell页面之间发送64格式的图像时,接收方ViewModel中的属性不受影响
下面是查询发送代码

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

以下是查询收据代码

[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();
        }
    }
}

虽然Image属性在ViewModel调度中带有值,但执行不会传递该属性,并且这是在执行因断点而停止时发生的

w46czmvw

w46czmvw1#

如果要将Image的字符串传输到导航页面的ViewMode l,可以使用Process navigation data using a single method来实现。
导航数据可以通过在ViewModel上实现IQueryAttributable接口来接收:SuppliersByProdectID。以下示例显示了实现IQueryAttributable接口的视图模型类:

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

有关详细信息,请访问https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation#pass-data。

相关问题