forum

Home / DeveloperSection / Forums / Button Click will not navigate to a new WPF page

Button Click will not navigate to a new WPF page

Anonymous User394123-Dec-2013

I cannot figure out why my button click is not navigating to a new page. I have tried writing this code several ways, but none of them work. EnlargedScreenCap is a WPF page and is in the same directory as the window in which I want to load it.

    private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)

    {

        NavigationService nav = NavigationService.GetNavigationService(this);

        ImageSource image = sender as ImageSource;

        EnlargedScreenCap esc = new EnlargedScreenCap();

        esc.SetImage(image);

        nav.Navigate(esc);

    }

Written like this I get a null reference exception because NavigationService is not getting initialized.

        private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)

    {

        ImageSource image = sender as ImageSource;

        EnlargedScreenCap esc = new EnlargedScreenCap();

        esc.SetImage(image);

        NavigationService nav = NavigationService.GetNavigationService(this);

        nav.Navigate(new Uri("//EnlargedScreenCap.xaml"), UriKind.RelativeOrAbsolute);

    }

When written like the above code, I get an invalid URI error, although nav is still null.


Updated on 23-Dec-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By