如何在运行时检索Panorama

如何在运行时检索Panorama

本文介绍了如何在运行时检索Panorama-Item的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以编程方式将项目添加到名为PanoramaCC的Panorama Control中.

I am programmatically adding items to my Panorama Control called PanoramaCC.

//function to create the panorama items in our view
private void showPanorama(string panoramaName)
{
    //create the panorama item and define it
    PanoramaItem genItem = new PanoramaItem();
    genItem.Height = 265;
    genItem.Width = 440;
    genItem.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(PanoramaItem_Tap);
    genItem.Name = panoramaName;

    //create the stackpanel for the panoramaitem
    StackPanel genStack = new StackPanel();
    genStack.Orientation = System.Windows.Controls.Orientation.Horizontal;
    //margin to be done
    genStack.Margin = new Thickness(0, -20, 0, 20);

    //load the image
    Image genImg = new Image();
    genImg.Height = 220;
    genImg.Width = 400;
    genImg.Stretch = System.Windows.Media.Stretch.Fill;
    genImg.Margin = new Thickness(20, 5, 20, 5);

    string path = "Assets/AppGraphics/CreditCards/" + panoramaName.ToString() + "Front.png";
    Uri uriR = new Uri(path, UriKind.Relative);
    BitmapImage imgSource = new BitmapImage(uriR);
    genImg.Source = imgSource;

    //add image into stackpanel
    genStack.Children.Add(genImg);
    //add stackpanel to the panoramaitem
    genItem.Content = genStack;
    //add the panoramaitem to the panoramaview
    this.PanoramaCC.Items.Add(genItem);
}

我遇到的问题是,在运行时我想检索当前正在查看的panoramaItem的名称并对其进行处理.我已经设法通过tap事件检索名称以进行导航,string name = ((PanoramaItem)sender).Name;,但这是一个不同的情况.我想检索名称,然后删除具有相应名称的项目.按下按钮应该删除当前选择的panoramaItem,这是我要达到的目的.

The issue I have is that during runtime I want to retrieve the name of the panoramaItem I am currently looking at and do something with it. I've managed to retrieve the name through the tap event for navigation purposes, string name = ((PanoramaItem)sender).Name; but this is a diffrent scenario. I want to retrieve the name and then delete the item with the corresponding name. Pressing a button should delete the currently selected panoramaItem, is what I'm trying to achieve.

推荐答案

您可以获取当前的 PanoramaItem 通过使用 SelectedItem 属性.您无需删除名称即可.

You can get the current PanoramaItem by using the SelectedItem property. You don't need to get the name to delete it.

PanoramaItem currentItem = myPanorama.SelectedItem as PanoramaItem;
if(currentItem != null)
{
   //if you want the name for other reasons
   string name = currentItem.Name;

   //Items returns an ItemsCollection object
   myPanorama.Items.Remove(currentItem);
}

这篇关于如何在运行时检索Panorama-Item的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 10:05