gpt4 book ai didi

c# - 如何在运行时检索全景项目的名称?

转载 作者:行者123 更新时间:2023-11-30 20:59:17 26 4
gpt4 key购买 nike

我正在以编程方式将项目添加到名为 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 的名称并对其进行处理。为了导航目的,我已经设法通过点击事件检索名称,string name = ((PanoramaItem)sender).Name; 但这是一个不同的场景。我想检索名称,然后删除具有相应名称的项目。按下按钮应删除当前选择的 panoramaItem,这就是我想要实现的目标。

最佳答案

可以获得当前的PanoramaItem通过使用 SelectedItem属性(property)。您无需获取名称即可将其删除。

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

关于c# - 如何在运行时检索全景项目的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15571728/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com