locked
How to show a popup in a selected Gridview item?

    Question

  • I have a popup which i want to show on top of a selected Gridview item ,which shows addition info about the clicked item. How can i achieve this using a normal popup ? 

    19karabo91

    Tuesday, June 10, 2014 6:16 AM

Answers

  • Try this:

    <GridView x:Name="MyGridView" SelectionMode="None">
      <GridView.ItemTemplate>
        <DataTemplate>
          <StackPanel>
            <TextBlock Text="{Binding}" IsTapEnabled="True" Tapped="TextBlock_Tapped"/>
            <Popup IsOpen="False" VerticalOffset="10" HorizontalOffset="20">
              <StackPanel Background="Red" Margin="10">
                <StackPanel Orientation="Horizontal" >
                  <TextBlock Margin="0 0 3 0">This is a popup about item </TextBlock>
                  <TextBlock Text="{Binding}"/>
                </StackPanel>
                <Button Content="Close Popup" Click="Button_Click"/>
              </StackPanel>
            </Popup>
          </StackPanel>                    
        </DataTemplate>
      </GridView.ItemTemplate>
    </GridView>
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
      List<string> MyList = new List<string>();
      MyList.Add("A");
      MyList.Add("B");
      MyList.Add("C");
      MyList.Add("D");
      MyList.Add("E");
      MyList.Add("F");
      MyList.Add("G");
      MyList.Add("H");
      MyList.Add("I");
      MyList.Add("J");
      MyGridView.ItemsSource = MyList;
    }
    
    Popup CurrentPopup = null;
    
    private void TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
    {
      if (CurrentPopup != null) CurrentPopup.IsOpen = false;
      TextBlock ThisTextBlock = sender as TextBlock;
      StackPanel ThisStackPanel = ThisTextBlock.Parent as StackPanel;
      Popup ThisPopup = ThisStackPanel.Children[1] as Popup;
      ThisPopup.IsOpen = true;
      CurrentPopup = ThisPopup;
    }
    
    private void Button_Click(object sender, RoutedEventArgs e)
    {
      CurrentPopup.IsOpen = false;
      CurrentPopup = null;
    }



    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, June 10, 2014 1:11 PM
    Moderator