locked
Passing QueryString Using XAML in windows phone 8 RRS feed

  • 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);
            
                }
    

    Note: 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:05 AM

All replies

  • Hi there!

    Take a look at this example:

    <Button Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top">
    			<Interactivity:Interaction.Behaviors>
    				<Core:EventTriggerBehavior EventName="Click">
    					<Core:NavigateToPageAction Parameter="HelloWorld!" TargetPage="App4.BlankPage1"/>
    				</Core:EventTriggerBehavior>
    			</Interactivity:Interaction.Behaviors>
    		</Button>

    That is how you do it with Blend 2013. Take note that this example works for the Windows Phone 8.1, where your retrieve navigation parameters like this:

            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                var parameters = e.Parameter;
            }

    Hope this helps.

    Cheers,

    Sam

    Monday, January 19, 2015 10:23 AM