locked
Accessing controls Inside of StackPanel in HubApp Template

    Question

  • This is my xaml view.

     <HubSection x:Name="section1" Width="700" Margin="0,0,100,0">
                    <DataTemplate>
                        <FlipView x:Name="pageFVFeaturedNews" ItemsSource="{Binding}" Tapped="pageFVFeaturedNews_Tapped" Margin="-40,-170,-150,-130">
                            <FlipView.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Tapped="StackPanel_Tapped">
                                    <Grid>
                                        <Image Source="{Binding image}" Stretch="Fill" Margin="0,130,0,0"/>
                                        
                                        <StackPanel VerticalAlignment="Bottom" Margin="0,300,0,0" Background="#7F000000">
                                            <Rectangle Fill="#FFFF0404" Height="4"/>
                                            <StackPanel Margin="200,0,0,0">
                                                <TextBlock Name="txtHeading" Foreground="White" Text="{Binding heading}" Margin="0,15,0,0" FontSize="50" VerticalAlignment="Bottom"  TextTrimming="WordEllipsis" />
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock Name="txtDate"  Foreground="White"  Text="{Binding date}" FontSize="12" Margin="0,10,0,0" />
                                                </StackPanel>
                                                <TextBlock Name="txtShortHeading"  Foreground="White" Text="{Binding short_heading}" TextWrapping="NoWrap" FontSize="16" TextTrimming="WordEllipsis"  Margin="0,0,0,50" />
                                            </StackPanel>
                                        </StackPanel>
                                    </Grid>
                                    </StackPanel>
                                </DataTemplate>
                            </FlipView.ItemTemplate>
                        </FlipView>
                    </DataTemplate>
                </HubSection>

    I needed a small help on how to extract subitems of Flipview control in windows store development.

    I have written a code for binding data in flipview control in .cs file

           

    List<MyImageData> ds = newList<MyImageData>();

                ds.Add(

    newMyImageData() { MyI_Uri = "Images/Pic1.png", MyText = "CLose"});

                ds.Add(

    newMyImageData() { MyI_Uri = "Images/Pic2.png", MyText = "Erase"});

                ds.Add(

    newMyImageData() { MyI_Uri = "Images/Pic3.png", MyText = "MyLogo"});

                         

             

    this.Mylist.ItemsSource = ds;

    Now how can I be able to extract the MyText Item in the selection changed property of the Flipview.


    Sumit Tuladhar

    Monday, June 09, 2014 5:28 PM

Answers

  • Add a selection changed event handler to the FlipView:

    <FlipView x:Name="pageFVFeaturedNews" ItemsSource="{Binding}" SelectionChanged="PageFVFeaturedNews_OnSelectionChanged"...

    and get the selected item from the SelectionChangedEventArgs:

    private void PageFVFeaturedNews_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                var selectedItem = e.AddedItems[0] as MyImageData;
                // access text by seletedItem.MyText
            }


    - Ram
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Monday, June 09, 2014 8:37 PM