locked
how to call the event of second page from master page in Windows Store using c#?

    Question

  • Hi ,

    i have a doubt regarding i have  button Controls in the master page and the Event handlers in the another page .how do i call the Events to the  master page from another page.please Suggest me in this

    Thanks


    m venkatasuresh

    Wednesday, October 15, 2014 7:07 AM

Answers

  • Hi Venkata,

    Per my understanding, you want to use the control in Frame using the control is master page. We cannot call the event handler in other page directly, but we can access the control in other page. See the following code to know how to.

    In MainPage.XAML

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <StackPanel Margin="0 40 0 0 ">
                <Button Content="Hello" Click="Button_Click"></Button>
                <Frame x:Name="BasicLayout" Height="200"/>
                <Frame x:Name="SpecificLayout" Height="300"/>
            </StackPanel>
    </Grid>

    In MainPage.XAML.cs

    private void Page_Loaded(object sender, RoutedEventArgs e)
            {
                BasicLayout.Navigate(typeof(First));
                SpecificLayout.Navigate(typeof(Second));
            }
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                First page = BasicLayout.Content as First;
                TextBox txt = page.FindName("txt") as TextBox;
                if (txt!=null)
                {
                    txt.Text = DateTime.Now.ToString();
                }
            }

    In First.XAML

     <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <StackPanel>
                <TextBlock Text="i'm in first page"></TextBlock>
                <TextBox x:Name="txt"></TextBox>
            </StackPanel>
    </Grid>

    If I misunderstand you, please feel free to let me know.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.


    Friday, October 24, 2014 2:56 AM
    Moderator

All replies

  • What exactlly are you trying to do?

    I don't think it makes much sense to have the EventHandler for a page that is currently being displayed on another page. You should perhaps have the EventHandler in the main page and hand everything the second page needs to know over to it when you navigate there.

    Wednesday, October 15, 2014 8:30 AM
  • Hi ,

    My requirement is i am having number of pages and the Main page i am using as a master page .I called all the pages to the master page but the Whatever the Event in the another page from Master page is not Firing..the thing is events are there in the Respective pages other than master page

    Simply to Say From the master page button needs to call the Another page event.

    Is that possible to do?




    m venkatasuresh

    Friday, October 17, 2014 1:19 PM
  • Hi Venkata,

    Per my understanding, you want to use the control in Frame using the control is master page. We cannot call the event handler in other page directly, but we can access the control in other page. See the following code to know how to.

    In MainPage.XAML

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <StackPanel Margin="0 40 0 0 ">
                <Button Content="Hello" Click="Button_Click"></Button>
                <Frame x:Name="BasicLayout" Height="200"/>
                <Frame x:Name="SpecificLayout" Height="300"/>
            </StackPanel>
    </Grid>

    In MainPage.XAML.cs

    private void Page_Loaded(object sender, RoutedEventArgs e)
            {
                BasicLayout.Navigate(typeof(First));
                SpecificLayout.Navigate(typeof(Second));
            }
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                First page = BasicLayout.Content as First;
                TextBox txt = page.FindName("txt") as TextBox;
                if (txt!=null)
                {
                    txt.Text = DateTime.Now.ToString();
                }
            }

    In First.XAML

     <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <StackPanel>
                <TextBlock Text="i'm in first page"></TextBlock>
                <TextBox x:Name="txt"></TextBox>
            </StackPanel>
    </Grid>

    If I misunderstand you, please feel free to let me know.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.


    Friday, October 24, 2014 2:56 AM
    Moderator