c# - 使用 App.current.MainPage 导航后图像源重置
问题描述
在登录时,我正在获取并存储一些属性(例如用户名、创建日期和电子邮件),包括设置插件中登录用户的图像路径(字符串类型)属性,并将其用作图像元素的来源主详细信息页面。当我转到其他页面并希望使用 Application.Current.MainPage 导航回主详细信息页面时,所有其他属性都将保留,但图像会清除,这显然意味着图像路径属性丢失。有没有人有这个问题,你是如何解决的?
这就是我在 JObject 和设置中存储图像路径属性的方式:
var imagepath = jObject.Value<string>("ImagePath");
Settings.Path = imagepath;
这就是我设置图像元素源路径的方式:
profileImg.Source =
string.Format(UrlConstants.url2,Settings.Path.Substring(1));
这就是我从其他页面导航到主详细信息的方式:
Application.Current.MainPage = new PeppyMasterDetail();
这是我的 Master Detail 页面的 Master Page 部分的构造函数:
public MasterPage()
{
InitializeComponent();
usernameLbl.Text = Settings.UserName;
emailLbl.Text = Settings.Email;
dateLbl.Text = "JOINED: " + Settings.Date;
profileImg.Source = string.Format(UrlConstants.url2, Settings.Path.Substring(1));
}
这是我的主详细信息页面的构造函数
public PeppyMasterDetail ()
{
InitializeComponent ();
mPage.listView.ItemSelected += OnItemSelected;
}
使用 Application.Current.MainPage 导航后,我希望仍然能够看到我的图像而不会被清除。
PS:当我使用 Navigation.PushAsync 或 Navigation.PopAsync() 进行导航时,不会发生此行为;
解决方案
推荐阅读
- c# - WPF 命令绑定到静态视图模型
- c# - 在堆栈上创建类的实例
- sql - 排除符合条件的记录
- xml - XPath - find an element based on its parent's sibling's child's text
- c - 使用指针打印模式的问题
- python - Python读取文件并识别UnicodeDecodeError的来源
- python - 如何使用 pydap 库收集 THREDDS 数据?
- php - 查找 WooCommerce 可下载产品文件的 src 以显示在音频短代码中
- google-apps-script - 谷歌网络应用程序中的属性服务对象不是字符串
- java - 在字符串中的双引号之间转义“转义字符”