locked
Change selected index in flipview on tap of button from other page

    Question

  • I have an app in which I have two child frames of mainframe which are shown on tap of a button. Each frame have different pages to show. I have a flipview in second frame which I want to control on tap of button on page in frame 1. i.e. If a button is tapped in first page I want to change the selected index in second page. I have three indexes in flipview but I am not able to achive this. Can anybody help? This is my code. Thanks in advance

    private void flipView_around_Me_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {            
                try
                {
                    int index = flipView.SelectedIndex;
                    System.Diagnostics.Debug.WriteLine("Selected Flip:" + index);

                    if (index == 0)
                    {
                        tabToShow("btn_Off1");
                    }
                    else if (index == 1)
                    {
                        tabToShow("btn_Off2");
                    }
                    else if (index == 2)
                    {
                        tabToShow("btn_Off3");
                    }
                }
                catch (Exception) { }
            }

            public void tabToShow(string tabName)
            {
                btn_On1.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                btn_On2.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                btn_On3.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

                switch (tabName)
                {
                    case ("btn_Off1"):
                        {
                            btn_On1.Visibility = Windows.UI.Xaml.Visibility.Visible;
                            flipView.SelectedIndex = 0;
                            break;
                        }
                    case ("btn_Off2"):
                        {
                            btn_On2.Visibility = Windows.UI.Xaml.Visibility.Visible;
                            flipView.SelectedIndex = 1;
                            break;
                        }
                    case ("btn_Off3"):
                        {
                            btn_On3.Visibility = Windows.UI.Xaml.Visibility.Visible;
                            flipView.SelectedIndex = 2;
                            break;
                        }
                }
            }

    Monday, March 9, 2015 9:57 AM

All replies

  • IN the page where the flipview is located, create a hidden XAML control of type textblock which the flipview's selectedindex is bound to. Also create a static property in the codebehind.  In the setter, change the textblock's value to the new value. 

    In the other frame's page, set the static property of the page containing the flipview.  This should update the texblock which then updates the selectedindex.

    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.

    Monday, March 9, 2015 3:18 PM
    Moderator
  • I tried this approach but could not get it working. Can you please provide a link or snippet? Thanks in advance
    Thursday, March 12, 2015 8:17 AM