locked
Passing QueryString Using XAML in windows phone 8

    Question

  • Dear Community members can you please tell me if there is any way to pass the query string between two pages using XAML when i press a button.. i know to do this using Click Event in my back End C# File.. but i want to know that is it possible by using only XAML of a button?

     Here is my code which im using to navigate to other page , its working properly but im unable to send query string through this..

    <Button Content="Button" FontFamily="Portable User Interface" Foreground="IndianRed">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Click">
                                <ec:NavigateToPageAction TargetPage="/Page2.xaml"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </Button>

    here is my page2 method that is expecting  query string from page1

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
            {
                base.OnNavigatedTo(e);
    
                string msg = "";
    
                if (NavigationContext.QueryString.TryGetValue("msg", out msg))
                {
                    MessageBox.Show(msg);
            
                }

    Please note that i want to do this using XAML code of my Button only, not in backend C# event of that Button

    Sunday, January 18, 2015 10:17 AM

Answers

  • Since your original code works and includes a NavigateToPageAction it should be pretty obvious that it is supported...

    The following code builds just fine for me in a project that targets Window Phone 8.0 provided that I have add references to Microsoft.Expression.Interactions.dll and System.Windows.Interactivity.dll:

    <Button Content="Button" FontFamily="Portable User Interface" Foreground="IndianRed"
                        xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <ec:NavigateToPageAction>
                                <ec:NavigateToPageAction.TargetPage>
                                    <Binding Path="Links[0].Uri.AbsoluteUri" 
                                             StringFormat="/Page2.xaml?msg={0}"/>
                                </ec:NavigateToPageAction.TargetPage>
                            </ec:NavigateToPageAction>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
    
    Please remember to mark helpful posts as answer and/or helpful.
    • Marked as answer by Sohail Hanfi Sunday, January 18, 2015 2:17 PM
    Sunday, January 18, 2015 1:37 PM

All replies

  • Hi Sohai , 

    You have to implement INOTIFYProperty Changed interface somewhere if you want to use XAMl Binding


    Sunday, January 18, 2015 11:09 AM
  • Try following code

    <ec:NavigateToPageAction TargetPage="/Page2.xaml?ID=Somevalue"/>


    Gaurav Khanna | Microsoft VB.NET MVP | Microsoft Community Contributor

    Sunday, January 18, 2015 11:31 AM
  • Gaurav Khanna

    its working in this way but i want to send a binded data in query string that is like. 

    {Binding Links[0].Uri.AbsoluteUri} // this is coming from an RSS feed

    if im doing it in this way <ec:NavigateToPageAction TargetPage="/Browser.xaml?msg={Binding Links[0].Uri.AbsoluteUri}"/> it is not passing the binded data 

    plz help

    Sunday, January 18, 2015 12:01 PM
  • You could use a Binding with a StringFormat as the TargetPage of the NavigateToPageAction as described here (see the NavigateToPageAction section): http://mmercan.com/blog/?p=15

    <ec:NavigateToPageAction>
                    <ec:NavigateToPageAction.TargetPage>
                        <Binding Path="Links[0].Uri.AbsoluteUri"
                        StringFormat="/Page2.xaml?msg={0}"/>
                    </ec:NavigateToPageAction.TargetPage>
                </ec:NavigateToPageAction> 
    

    Please remember to mark helpful posts as answer and/or helpful.
    Sunday, January 18, 2015 12:18 PM
  • it says.. NavigateToPageAction is not supported in Windows phone Silverlight project
    Sunday, January 18, 2015 12:51 PM
  • Since your original code works and includes a NavigateToPageAction it should be pretty obvious that it is supported...

    The following code builds just fine for me in a project that targets Window Phone 8.0 provided that I have add references to Microsoft.Expression.Interactions.dll and System.Windows.Interactivity.dll:

    <Button Content="Button" FontFamily="Portable User Interface" Foreground="IndianRed"
                        xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <ec:NavigateToPageAction>
                                <ec:NavigateToPageAction.TargetPage>
                                    <Binding Path="Links[0].Uri.AbsoluteUri" 
                                             StringFormat="/Page2.xaml?msg={0}"/>
                                </ec:NavigateToPageAction.TargetPage>
                            </ec:NavigateToPageAction>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
    
    Please remember to mark helpful posts as answer and/or helpful.
    • Marked as answer by Sohail Hanfi Sunday, January 18, 2015 2:17 PM
    Sunday, January 18, 2015 1:37 PM
  • Magnus (MM8) its working perfectly now ..Really thanks for your help 
    Sunday, January 18, 2015 2:19 PM