---
title: "Button Click will not navigate to a new WPF page"  
description: "Button Click will not navigate to a new WPF page"  
author: "Anonymous User"  
published: 2013-12-23  
updated: 2013-12-23  
canonical: https://www.mindstick.com/forum/1839/button-click-will-not-navigate-to-a-new-wpf-page  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# Button Click will not navigate to a new WPF page

I cannot [figure](https://yourviews.mindstick.com/view/87536/what-are-ghosts-jobs-and-how-to-figure-out-them) out why my [button click](https://www.mindstick.com/forum/790/form-gets-submiited-twice-on-button-click) is not navigating to a new page. I have tried [writing](https://www.mindstick.com/articles/12997/5-essential-tips-on-resume-writing-for-business-analysts) this code several ways, but none of them work. EnlargedScreenCap is a WPF page and is in the same [directory](https://www.mindstick.com/forum/226/how-to-get-application-directory-using-c-sharp-csharp) as the [window](https://www.mindstick.com/forum/161285/how-does-the-window-console-object-work-in-javascript) in which I want to load it.

[private](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) 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](https://www.mindstick.com/forum/158621/what-is-a-null-reference-exception-and-how-can-it-occur-in-an-asp-dot-net-mvc-project) 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.

## Replies

### Reply by Pravesh Singh

Hi Brad,\

I do not think you should be creating the NavigationService the way you are doing. Also if you want to enable navigation all this should be done in a Frame

<Frame x:Name="_mainFrame" />

Then you could do something like

_mainFrame.NavigationService.Navigate(new Uri("EnlargedScreenCap.xaml", UriKind.Relative));

Without the double slashes in front.


---

Original Source: https://www.mindstick.com/forum/1839/button-click-will-not-navigate-to-a-new-wpf-page

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
