Navigate to another page on button click - visual-studio

I am developed the Windows mobile application I've added the button for VS blend 2015 , but there's no button navigate to option how to bind to my button for the page sub.xaml
<Button x:Name="button" Content="Enter" Height="42" Margin="122,-113,0,0"
VerticalAlignment="Top" Width="144" Foreground="#FF50CBC5"
Background="#FF0F0E0E" HorizontalAlignment="Left"/>

The hyperlink button gives you the option to navigate to another page onclick.
This screen shot is from Blend.
So change your mark up as follows, including the generated Click handler.
<HyperlinkButton x:Name="button" Click="HyperlinkButton_Click"
Content="Enter" Height="42" Margin="122,-113,0,0"
VerticalAlignment="Top" Width="144" Foreground="#FF50CBC5"
Background="#FF0F0E0E" HorizontalAlignment="Left"/>
Then in your cs, you need to direct the navigation.
// Button to navigate to sub.xaml page.
private void HyperlinkButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
// Navigate back to sub.xaml page.
this.Frame.Navigate(typeof(SubPage));
}

You will have a Click event for button. In that click event, write the code as
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/sub.xaml", UriKind.RelativeOrAbsolute));
}

You can do this using following steps.
1st Step - add a new button on your window and change the properties as you wish.
2nd Step - double click on that button. then you will go to the cs file like this.
private void Button_Click(object sender, RoutedEventArgs e)
{
}
3rd Step - create new object of window that you want to navigate and open that, then close current window
private void Button_Click(object sender, RoutedEventArgs e)
{
NewWindow newWindow = new NewWindow();
newWindow.Show();
this.Close();
}
Thanks.

Related

Toggle AppShell on button click in Xamarin.forms

I have AppShell that I pull from the side to show but I want to achieve this on button click to toggle AppShell. I am not using the default AppShell navbar so I disabled the Shell.NavBarIsVisible="False" since its not needed.
I want to achieve this with the custom button to toggle AppShell.
You can open it with this , true to open or false to close
private void Bottommenu3_Clicked(object sender, EventArgs e)
Shell.Current.FlyoutIsPresented = true;
}

Xamarin - how i can i make my button display different text each time it is clicked?

I have a button added using <Button Text="Next" Clicked="Button_Clicked"></Button> How can I make my button display different text each time it is clicked?
You need to give a name to your Button in order to get hold of it in your Button_Clicked method.
<Button x:Name="MyButton" Text="Next" Clicked="Button_Clicked" />
Then in your code behind:
private void Button_Clicked(object sender, EventArgs args)
{
MyButton.Text = "Hello, World!";
}

How to go to an xaml page by clicking on the button in WebBrowser control in Windows Phone 7 or 8

I have a XAML Page with a WebBrowser tag. WebBrowser has few text boxes and a button, here my question is after clicking on that button i have to go to a XAML page. How can i do this?
By clicking the button in WebBrowser, i want to go to a XAML Page which is in solution file.
Please help me on this.
I believe you can solve this by listening to the WebBrowser.Navigating event. First do:
myWebBrowser.Navigating += myWebBrowser_Navigating;
Then in the handler method check if the uri navigated to is the pointed to by that button:
private void myWebBrowser_Navigating(object sender, NavigatingEventArgs e)
{
if(e.Uri.AbsolutePath == URI_OF_BUTTON) {
NavigationService.Navigate(new Uri("/otherPage.xaml", UriKind.Relative));
}
}
It sound like Page Navigation.
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Pasta.xaml", UriKind.Relative));
}

Hyperlink button website

I need to put button that after click moves user to website. Can someone tell me what should I put into vb and in xaml?
<HyperlinkButton Content="Click here to learn about Silverlight" NavigateUri="http://www.silverlight.net" TargetName="_blank" />
You can do it also in C#
private void HyperlinkButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
var task = new Microsoft.Phone.Tasks.WebBrowserTask
{
URL = "http://siteaddress.com",
};
task.Show();
}

How to create a small Windows Phone 7 app with click event

I am a newbie in windows phone app and need to create a small Windows Phone 7 app. The app will perform the following task
App Screen has an image "image1' ,when i press on 'image1' it will shows a second image 'image2'
When I press on image2 it will shows image1 and so on
My XAML code
<Button Click="Button_Click">
<Image Source="resourse/image1.jpg"/>
</Button>
C# code
namespace Test
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// here will shows the 'image2' and also give click event to turn 'image1'
}
}
}
Please help
I would tackle this by having a couple of images in your XAML:
<Button Click="Button_Click">
<Grid>
<Image x:Name="imageOne" Source="resourse/image1.jpg"/>
<Image x:Name="imageTwo" Source="resourse/image2.jpg"
Visibility="Collapsed"/>
</Grid>
</Button>
The use of x:Name causes visual studio to generate a field for each image. The second image is 'collapsed', i.e. hidden.
You click handler then does the following:
private void Button_Click(object sender, RoutedEventArgs e)
{
if (imageOne.Visisbility == Visibility.Visible)
{
imageOne.Visisbility = Visibility.Collapsed
imageTwo.Visisbility = Visibility.Visible
}
else
{
imageOne.Visisbility = Visibility.Visible
imageTwo.Visisbility = Visibility.Collapsed
}
}
On each click it toggled the visibility of each image.
This is easier than changing the Source of the image, which involves URIs etc...

Resources