【问题标题】:How to retrieve the name of a Panorama-Item at runtime?如何在运行时检索全景项目的名称?
【发布时间】:2013-03-22 13:36:01
【问题描述】:

我正在以编程方式将项目添加到名为 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,这是我想要实现的。

【问题讨论】:

    标签: c# windows-phone-8 panorama-control


    【解决方案1】:

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

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

    【讨论】:

    • derp 我现在正用力捂脸。我看到了全景控件的 selectedItem,但我的大脑没有识别它。谢谢
    • 知道当 SelectedItem 是模型类时如何获取 PanoramaItem 吗?我只使用 ItemTemplate 和数据绑定,因此我的模型对象列表显示为 PanoramaItem,这意味着 SelectedItem 以及 Items 仅引用我的模型类。这意味着上面的代码总是导致 currentItem 为空。
    • 我没有尝试从全景项目中检索 SelectedItem,但this behaviour 可能会有所帮助以及this workaround
    • 我已经使用了您链接的解决方法。反正我新建了一个question,也许你有时间看看。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-21
    • 1970-01-01
    • 2016-02-10
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多