how to make link between buttons and pages in WPF windows application? - c#

i had look at that article
http://msdn.microsoft.com/en-us/library/vstudio/ms750478%28v=vs.100%29.aspx
but i couldn't get a practical way to do what i want.
i wish i got a simple and direct way to do what i want

Create a Click event handler for each button that you want to link to a page. In the handler, write the following code:
NavigationService.Navigate(new Uri("YourPageHere.xaml", UriKind.Relative));
I really think that you should try to follow the steps on that page one by one, though.

Related

What is the most efficient way to Navigate to a XAML page? wp8

Suppose, I have two XAML page: MainPage.xaml & Page1.xaml.
For navigating to Page1.xaml, I always use this code:
Page1 mynewPage = new Page1();
this.Content = mynewPage;
But I see people using other codes for navigating purpose. Am I doing this in an inefficient way? What's the most efficient way to do this?
use this.NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
In that case you have not control about, for instance going back,in your case have to create code to manage the navigation by yourself, and you might to need to store the information of each page at a time, that is automatic when you do it.
Apart there are transitions between pages that are great to show the user that the page is changing. Of course you can create your own transitions but at the end you are creating the navigation by yourself.
With navigation you can control the events of Navigating and navigated and use them to initialize the page, etc.
In windows phone 8, you should use "NavigationService". NavigationService contains methods, properties, and events to support navigation and implemented by Microsoft.
Your code just updates content. It doesnt keep navigation history. So, you cant use back button unless override. You cant pass parameter to another view or you cant know navigation sucessfully ended.
To sum up, navigation service offers all of these features and mores. For detail information , you can checkout in app navigation model from here: In-app navigation for Windows Phone 8

How do you navigate to a new page in a metro app?

trying to write a metro app in C# right now. Ran into a problem while trying to navigate to a new page.
<HyperLinkButton NavigateUri="foo.xaml"/>
doesn't work, as the NavigateUri field doesn't exist.
The Windows.Navigate namespace isn't available either, so no luck there. What's the proper way to go to a new page in my app in metro?
You can handle the Button control's Click event (in fact, you can use all events with the following code) because Metro's HyperLink button only inherits the ButtonBase class without any special properties or events, such as NavigateUri.
If you want to navigate to another page in your metro app, add a frame in the .xaml page and put this code in the button's event handler:
this.Frame.Navigate("VideoStoryCreator.ComposePage");
There are two ways of Navigating to another page -
Client app way ->
You'll implement this in click event -
var page = new PageName();
Window.Current.Content = page;
Similar to Silverlight Navigation
If you are using Frame/Page Navigation then you can do it like this -
Create a shell page (master page) with the element declared. Then instead of creating new pages with create .
The easiest way to do this is to replace UserControl with Page
This is nicely explained in this tutorial -
http://www.markermetro.com/2011/11/technical/windows-8-metro-style-apps-implementing-navigation-with-xaml/
Hope it helps!
Regards,
Bhavik
Handle the Click event on the button and then call the Navigate method on your Frame
just type the following code in your click event
this->Frame->Navigate(TargetPageName::typeid,this);

Is it possible to put a "Clickable Link" inside of a Systray Notification Bubble?

Not much to add to this. Have an example?
No. There are two options though. The simplest is to just use the click event of the balloon to trigger the event you require. The more complicated one is to create a custom balloon within which you can present a link.
See http://www.codeproject.com/KB/miscctrl/taskbarnotifier.aspx for an example of how this could be accomplished.

Loading .aspx into a Panel/UpdatePanel

I'm currently working on a web-based game using ASP.NET and C#. Previously, I've been just organizing the various game screens(start, hi-score, results, etc) into individual Panels nested within a main UpdatePanel and showing/hiding the appropriate Panels as the game progresses. However, I've severely underestimated the scale of the game and I'm gonna have to break it down to more manageable chunks.
My idea now is to have a Main.aspx with an empty UpdatePanel and I'll load the various screens as individual .aspx files into it. Kinda like with WinForms I think, when you create another new WinForm and add it to the current parent form.
I've been trying to find how to get about doing this in the code-behind, but I'm still at a lost. I could probably do this with Response.Redirect, but then there would be the usual flicker when the new page loads, which is something I want to avoid.
I did come across something interesting called a UFrame but that seems to work in the HTML instead of the code-behind.
I appreciate any help or suggestions in this matter, and apologize if this has been asked before. Thank you.
Edit: With regards to womp's answer, .ascx seem to be a step in the right direction for me. I successfully got my Startscreen control control up and running inside the Main.aspx. However, another problem has popped up, where the screen just goes blank when I try to add another usercontrol to a panel inside Main.aspx upon a button click.
The event handler I have for a button in the Startscreen control is:
protected void Btn_Arcade_Click(object sender, EventArgs e)
{
this.Parent.Controls.Add(LoadControl("Arcade.ascx"));
}
I'm not too sure if there's anything wrong with that, but the Parent in this case is basically what I called the GameContentPanel that resides within Main.aspx's UpdatePanel.
I don't think it's a problem with the HTML fudging up either, since I tested it by loading it first instead of the Startscreen, and everything showed up fine.
I've also tried loading both controls together at the start in Main.aspx, and both controls load correctly as well.
Can the "screens" be .ascx usercontrols? You can load a usercontrol into a panel using LoadControl("~/path/to/myControl.ascx"), and then those controls can take part in the lifecycle of the main page.
If they really have to be in separate .aspx pages, then you might need to look at using an iframe, or else maybe rethinking your approach. Webforms apps were designed to have lots of things happening inside the context of one page/form, and not transferring control back and forth to multiple pages.

tabbed document interface in WPF using only on-board means?

I've seen two threads here about TDI & C#. Both of them didn't really answer the questions I have ...
Since TDIs are pretty much like a standard nowadays, I can hardly imagine, that I have to buy a special control (like AvalonDock or SandDock).
This must be possible with built in the tab-control(?) somehow! I don't need special features like dock- and draggable tabitems. Just open every form in a new tab. Thats it.
Like putting every forms content controls into user controls and by request (button, menu click ...) add a new tab and put the corresponding user control on it ... something like this.
How would you do it? This can't be THAT complicated (even for me) or am I missing something?!
thanks a lot!
Maybe Josh Smith's article on MVVM can give you an idea how to design such user interface. Example being built there is kinda tabbed document interface so you can use it as a starting block.
It's not that hard. It seems hard because there are a lot of different ways to do it.
Try this:
<TabControl x:Name="documentArea"/>
Handler for AddForm button:
private void AddFormClick(object sender, RoutedEventArgs e)
{
object form = GetNewForm();
documentArea.Items.Add(form);
}
That's it. You have to implement GetNewForm() in one of two ways. Have it return a user control that displays the form.
OR better yet, have it return your document that you want to display. Use a DataTemplate to select the controls to use for displaying this document. This method is going to be more complex to set up.

Categories

Resources