WP8.1全景视图框所选索引

本文关键字:索引 视图 全景 WP8 | 更新日期: 2023-09-27 18:24:43

如何从全景项目中的ViewBox获取WP8.1上的选定索引或项目?这是我的xaml和我的c#代码

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#点击事件

private void Border_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MessageBox.Show("Tapped!: " + "(number) item");
        }

我可以在互联网上找到一些提示,但它们都是关于LongListSelector

WP8.1全景视图框所选索引

您希望为哪个控件获取所选项目?如果是Panorama,则可以为包含PanoramaItem的Panorama控件命名,并使用Panorama.SelectedIndex属性。

我在发布的XAML上没有任何其他控件具有选定项的概念。。。

首先,您必须提供全景项目的标题名称,才能轻松获得所选标题。然后在全景选择更改事件上调用此片段。

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