none
Xaml page over another xaml page

    Question

  • Hi All,

     I am having a TextBlock in Page.Xaml, On MouseEnter event for this TextBlock I need to display Test.Xaml on Page.Xaml.

    Test.Xaml should cover only a part of Page.Xaml as there are only few controls on Test.Xaml.

    On MouseLeave event I need to remove Test.Xaml from Page.Xaml.

     

    Thanks in Advance,

    Tuesday, May 01, 2012 5:05 AM

Answers

  • Hi ,

      You can place another container dynamically in your Page. For example , use a canvas , and set its content to Test.xaml content.

    Here's my sample code.

      private void textBox1_MouseEnter(object sender, MouseEventArgs e)
            {
                Canvas c = new Canvas();
                c.HorizontalAlignment = HorizontalAlignment.Center;
                c.VerticalAlignment = VerticalAlignment.Center;
                c.Width = 500;
                c.Height = 500;
                c.Children.Add(new Test());
                this.LayoutRoot.Children.Add(c);
            }

    And to remove this object, you can just write the removal code in some button click on the test page.

    Hope it Helps Laughing

    Tuesday, May 01, 2012 5:18 AM

All replies

  • Hi ,

      You can place another container dynamically in your Page. For example , use a canvas , and set its content to Test.xaml content.

    Here's my sample code.

      private void textBox1_MouseEnter(object sender, MouseEventArgs e)
            {
                Canvas c = new Canvas();
                c.HorizontalAlignment = HorizontalAlignment.Center;
                c.VerticalAlignment = VerticalAlignment.Center;
                c.Width = 500;
                c.Height = 500;
                c.Children.Add(new Test());
                this.LayoutRoot.Children.Add(c);
            }

    And to remove this object, you can just write the removal code in some button click on the test page.

    Hope it Helps Laughing

    Tuesday, May 01, 2012 5:18 AM
  • Thank You, Phani. I got it could you please help for the removal code too.

    Tuesday, May 01, 2012 5:51 AM
  • Hi ,

       In the MainPage , i changed the code to this.

    {

    Canvas c = new Canvas();
                c.HorizontalAlignment = HorizontalAlignment.Center;
                c.VerticalAlignment = VerticalAlignment.Center;
                c.Width = 500;
                c.Height = 500;
                c.Children.Add(new Test(this,c));   // i changed it here. I am passing the main page reference 
    // and the canvas displaying the data this.LayoutRoot.Children.Add(c);

    }

    I added a button in the TestPage , which will remove the page from the screen. On clicking that button, the canvas will be removed. You can customise it to your needs. This just shows you the idea.

           MainPage m;
            Canvas cc;
            public Test(MainPage obj, Canvas c)
            {
                InitializeComponent();
                m = obj;
                cc = c;
            }
    
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                m.LayoutRoot.Children.Remove(cc);
            }
    
           
    Hope it Helps
    Laughing

    
    
    Tuesday, May 01, 2012 11:22 AM
  • Thanks for your reply.

    I have the button in Test.Xaml , but I want to write its event in the MainPage.Xaml.

    In the MainPage.Xaml, I am writing as below,

    ctlTest test = new ctlTest();

    test.btn_Save.Click +=new RoutedEventHandler(btnSave_Click);

    But btnSave_Click event is not executing.

    Any help.

     

    Thanks,

    Wednesday, May 02, 2012 3:20 AM
  • Is there any other way to remove Test.xaml from the main page instead of button_click event of Test.xaml.

    Bcoz there is nothing mandatory on the test.xaml to select or click.

    I tried MouseLeftButtonUp, MouseLeftButtonDown on MainPage.xaml. But no use.

    Any help.

    Thanks,

    Friday, May 04, 2012 6:36 AM

  • Hi ,
    This was the code i first suggested. If you notice, that canvas is local to the mouse enter.
    Thats the reason you cant access that outside in Mainpage.
    private void textBox1_MouseEnter(object sender, MouseEventArgs e)
           
    {
               
    Canvas c = new Canvas();
                c
    .HorizontalAlignment = HorizontalAlignment.Center;
                c
    .VerticalAlignment = VerticalAlignment.Center;
                c
    .Width = 500;
                c
    .Height = 500;
                c
    .Children.Add(new Test());
               
    this.LayoutRoot.Children.Add(c);
           
    }

    Now bring the Canvas c outside the textBox1_MouseEnter .
    That way, you will be able to access the object c outside also.
    Then in your MouseLeftButtonDown event, check if c is null , and if it is not, remove the canvas from the layout root.

    Hope it Helps Laughing


    Friday, May 04, 2012 9:42 AM