简体   繁体   English

WP8.1 Panoramaitem Viewbox选定的索引

[英]WP8.1 Panoramaitem Viewbox selected index

How can I get the selected index or item on WP8.1 from a ViewBox in a PanoramaItem? 如何从PanoramaItem中的ViewBox获取WP8.1上的选定索引或项目? Here is my xaml and my c# code 这是我的XAML和我的C#代码

XAML XAML

<phone:PanoramaItem Orientation="Horizontal" Background="White">
                <!--Double wide Panorama with large image placeholders-->
                <Viewbox x:Name="Myitem" Height="800" Margin="0,-30,0,0" Width="912" >
                    <Border Height="800" Width="912">
                        <ScrollViewer Margin="0,0,0,177">
                            <StackPanel Margin="0,0,16,0" Orientation="Vertical" VerticalAlignment="Top" Height="1722">
                                <StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
                                    <Border Height="100" Width="100" Margin="12,0,0,0">
                                        <Border.Background>
                                            <ImageBrush Stretch="Fill" ImageSource="Assets/Tiles/stib-pic0.gif"/>
                                        </Border.Background>
                                    </Border>
                                </StackPanel>
                                <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Margin="0,12,0,0">
                                    <Border Height="100" Width="100" Margin="12,0,0,0" Tap="Border_Tap">
                                        <Border.Background>
                                            <ImageBrush Stretch="Fill" ImageSource="Assets/Tiles/stib-pic1.gif"/>
                                        </Border.Background>
                                    </Border>
                                    <Border Height="100" Width="100" Margin="12,0,0,0">
                                        <Border.Background>
                                            <ImageBrush Stretch="Fill" ImageSource="Assets/Tiles/stib-pic2.gif"/>
                                        </Border.Background>
                                    </Border>
                                    <Border Height="100" Width="100" Margin="12,0,0,0">
                                        <Border.Background>
                                            <ImageBrush Stretch="Fill" ImageSource="Assets/Tiles/stib-pic3.gif"/>
                                        </Border.Background>
                                    </Border>
                                    <Border Height="100" Width="100" Margin="12,0,0,0">
                                        <Border.Background>
                                            <ImageBrush Stretch="Fill" ImageSource="Assets/Tiles/stib-pic4.gif"/>
                                        </Border.Background>
                                    </Border>
                                </StackPanel>
                            </StackPanel>
                        </ScrollViewer>
                    </Border>
                </Viewbox>
            </phone:PanoramaItem>

C# Tap event C#Tap事件

private void Border_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {

            MessageBox.Show("Tapped!: " + "(number) item");
        }

I could find some tips on internet but they were all about LongListSelector 我可以在互联网上找到一些提示,但它们都与LongListSelector有关

For which control do you want to get the selected item? 您要获得哪个控件的所选项目? If it is the Panorama, then you can give a name to the Panorama control containing the PanoramaItem and use Panorama.SelectedIndex property. 如果是Panorama,则可以给包含PanoramaItem的Panorama控件命名,并使用Panorama.SelectedIndex属性。

I don't any other control on the posted XAML that has a notion of a selected item... 我对发布的XAML上没有任何其他具有选定项目概念的控件...

first of all you will have to provide header name of panorama item to easily get the selected header. 首先,您必须提供全景图项目的标题名称,才能轻松获取所选标题。 and then call this snippet on panorama selection changed event. 然后在全景图选择更改事件上调用此代码段。

var selectedItem = (PanoramaItem)(sender as Panorama).SelectedItem;
string item=selectedItem.Header.ToString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM