答案 0 :(得分:1)
您可以使用PhoneApplicationService
来执行此操作。
例如:
假设您从class A
导航到class B
在class B
中,在导航回A类之前,请设置
PhoneApplicationService.Current.State["showImage"] = true;
在class A
中,实施OnNavigatedTo
来处理它:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (PhoneApplicationService.Current.State.ContainsKey("showImage"))
{
bool showImage = (bool)PhoneApplicationService.Current.State["showImage"];
if (showImage)
{
this.YourImage.Visibility = System.Windows.Visibility.Visible;
}
else
{
this.YourImage.Visibility = System.Windows.Visibility.Collapsed;
}
PhoneApplicationService.Current.State.Remove("showImage");
}
}
修改强>
对于多张图片,您可以尝试以下方法:
在class B
中,不是将bool
传递给PhoneApplicationService
,而是传递Dictionary
个bool,每个bool代表一个图像的状态:
var showImage = new Dictionary<int, bool>();
showImage[1] = true;
showImage[2] = false;
showImage[3] = true;
PhoneApplicationService.Current.State["showImage"] = showImage;
在class A
中,为图片创建字典:
private Dictionary<int, Image> _images = new Dictionary<int, Image>();
然后在其构造函数中,使用您的图像填充词典:
InitializeComponent();
_images[1] = YourImage1;
_images[2] = YourImage2;
_images[3] = YourImage3;
在class A
&#39; OnNavigatedTo
中,执行:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (PhoneApplicationService.Current.State.ContainsKey("showImage"))
{
var showImage = PhoneApplicationService.Current.State["showImage"] as Dictionary<int, bool>;
if (showImage != null)
{
foreach (var key in showImage.Keys)
{
if (_images.ContainsKey(key))
{
if (showImage[key])
{
_images[key].Visibility = System.Windows.Visibility.Visible;
}
else
{
_images[key].Visibility = System.Windows.Visibility.Collapsed;
}
}
}
}
}
}
如果您愿意,可以更改词典的键,以获得更具代表性的字符串。
希望它有所帮助! :)