Silverlight : Issue with Childwindow and navigation framework - silverlight

could someone help me with childwindow and Navigation?
I created a childwindow from code and set its content as
ChildWindow CW = new ChildWindow();
CW.Content = new MainPageMenu(param1);
Here "MainPageMenu" itself is a Silverlight Page with a "navigation:Frame"
In the constructor, i navigate to various pages according to "param1" .
As i navigate to the desired page , the ie address bar shows the updated uri.
Should it show that? as the page is navigated in a childwindow......?
This works fine for first time. Once i close the childwindow and reopen with diff "param1" to navigate to other page
it never gets navigated..!!! it shows the same page as navigated to for the first call...
there is no error at line -
this.ContentFrame.Navigate(u);
in the constructor.
Is this a bug in navigation framework or i am supposed to something else to achieve this ?
Please help.

I see you already figured out that JournalOwnership is th key here. But just for a bit more background so this is less magic and more algorithm, here's how the Navigation Framework figures out whether to integrate with the browser journal, based on what Frame.JournalOwnership is set to.
JournalOwnership.Automatic (the default) - if the Frame is a "top level" Frame, it will navigate with the browser journal. If it's not, it won't. "Top level" means that if it walks up the visual tree it does not find any other Frame along the way.
JournalOwnership.OwnsJournal - the Frame will always own its own journal and not attempt to interact with the browser's journal.
JournalOwnership.UsesParentJournal - the Frame will always integrate with the browser. If it is not a top-level Frame this causes an Exception to be thrown.
So what's interesting about ChildWindow is that when Frame walks up the visual tree to see if it's a "top-level" Frame, it won't find one (because Popup is not rooted in the visual tree in the same way, and ChildWindow uses a Popup). Hence, it will think it's top-level (which may not really be correct in this case, but what else could it do?) so it will integrate with the browser journal.

Related

WPF Pages Slide

I have an application that is made using WPF, i have multiple pages and a form that contains a frame, and i load the pages on a frame, and each page has back and next buttons.
what i want to do is to animate the navigation of the pages on the frame in a way when i press Next, the current page slides to the left and the following page slides also to the left and replacing the the current page, and when i press back the current page slides to the right and the previous page slides to the right replacing the current page.
how to do that?
I may be proven wrong here but I don't believe WPF exposes a way to implement this easily. There are methods for overriding existing transition animations in UWP.
For WPF you can handle this one of two ways...
Start the animation of the page sliding out. When the animation is
complete let it fire an event that will then call frame to change
pages.
Have the page offset by default and perform the animation to slide it
in to it's original spot.
or....
Capture the Navigating event of the frame, monitor NavigationMode, call the animations, make the navigation wait or mark e.Handled == true and recall it after with a flag that says it can continue.
Do the same for transitioning in.
Here's the problem; you won't have both pages on the screen at the same time and you'll have to write some fancy transitioning code to make all this work correctly. I would go as far as introducing custom controls with interfaces or DependencyProperties that have the transitioning functions embedded etc.
That said; I have had this problem in the past and to be fair I just gave up on the Frame control and pages and did it all manually. In the end it felt faster, easier to maintain, and I was able to achieve any effect I wanted.
So if you want my honest answer just don't use Frame and do it all manually... (This is speaking for WPF only. UWP has other features and more reasons to use the built in navigation than WPF does.)
Well, I believe the simplest solution would be to drop using Frames and implement your own navigation mechanism using something along the lines of the TransitioningContentControl (so you don't have to implement the transitions from scratch).
Basically, you'd have an list of your controls, an TransitionContentControl and two buttons (back and forward). So all you'd have to do is handle the clicks on the buttons and set the Transition accordingly (eg. when back button is pressed set it to Left and load the previous page).

How to make WPF page navigation code look better?

I want to make a program by WPF which includes several pages.
I have a Window and several Pages now.
In order to navigate, I use
this.Content = new Page1();
in the main window (from Window to Page), and
((Window)this.Parent).Content = new Page1();
between pages (from Page to Page), because Page can only be sub-element of Window or Frame.
However, the second line of code above looks quite ugly.
Is there a better way to achieve the same goal?
I have coded from several Windows Phone applications before, and I think it might be better to navigate between Pages rather than hide/show elements (such as Grids).
If your navigation code is on your Page class, either :
move it to the window class
create an event in the Page class, and react to it on the Window class.
Is there any reason why you can't just put a Frame in your Window ?
You could use NavigationService.
http://msdn.microsoft.com/en-us/library/ms750478.aspx
http://www.paulstovell.com/wpf-navigation
Maybe this could help:
http://azerdark.wordpress.com/2010/04/23/multi-page-application-in-wpf/

WPF root element is not valid for navigation

I am converting a WPF XBAP app to a WPF desktop app. I have it running on the desktop, but am now trying to change the Page references to Window references.
'MyApp.StartForm' root element is not valid for navigation.
I have tried creating a simple version of this app and converting that, and this works fine, so there must be something within the XAML that is causing this when using Window tags. My question relates to how I can investigate this. Currently, all I get is this error, accompanied by a "No Source Available" screen; no stack locations are shown and "Show Disassembly" doesn't work. Other than systematically commenting out individual chunks of XAML until it works, is there a way to work out what this issue is?
Navigation in a WPF application can only be done between pages. The error shows up because you're trying to "navigate" to what is now a Window, and this isn't possible.
Instead of converting your Page into a Window, create a new Window with a Frame control in it. A Frame can be used to host your existing pages - which should stay exactly as they are, and not be changed into Windows.
Its not entirely accurate about it not being possible to host a window in a frame, the following code will do it for you
public void HostWindowInFrame(Frame fraContainer, Window win) {
object tmp = win.Content;
win.Content = null;
fraContainer.Content = new ContentControl() { Content = tmp };
}
please check StartForm having the page as root element or some other else. I am having the same. I have check the page which has to be navigated. I declare that page as window.

A better way to show different wpf pages in mainWindow?

I have several Wpf pages in my project, these pages have different forms and ui control indide theme. The image below shows the mainWindow and there are two button.
I want to show a specific page when I click on + or Edit button using the Frame control which is highlighted.
apparenatly this woks:
Page1 me = new Page1();
mainFrame.Content = me;
But it has an IE navigation sound and a toolbar appears after going to page2.
any better way to show diffrent pages and not using a frame?
You may want to convert the Page into a UserControl. You can then put that control inside some other container, such as a Grid. You'll have to manually swap out the pages in the container when navigating, but it looks like you're doing that anyway.
The purpose of the Frame control is to allow navigation. If you don't want navigation, then don't use Frame. You can turn off the navigation toolbar, but that won't actually disable navigation - there are mouse buttons and keyboard shortcuts for navigating back.
If you just want to host a UI element without navigation, use something simpler, like a Border element - put the content in its Child property. You can change the Child as many times as you like at runtime.
I was able to set the frame control's NavigationUIVisibility to Hidden. This solved the problem for me. I am using Visual Studio 2010 though so it might not be applicable to older VS versions.
Ian Griffiths, what you suggest increases the workload on the developer substantially. And you are stepping outside of the underlying paradigm of XAML.
In my case I'm developing a game application and have chosen WPF as the UI platform as much as possible. For me that means a intro screen, character select, etc. The purpose of Pages is to encapsulate the navigational need of such an application.
I suspect your downvote is due to your statement "If you don't want navigation...". Upon re-reading the original posters question I see he does want navigation, he just wants it on his own terms. I would have voted you down too. YotaXP's solution neglects the issues with using a User Control, particularly if it may contain other User Controls. It looks like Chris Calvert came up with an actual solution to the poster's issue within the parameters of the problem.
I would be curios if I could override the navigation hotkeys and such within the existing paragimn but that's properly in its own thread.

Virtualize WinForms ScrollableControl - Expensive Child Items

I am building a PDF Viewer using the Atalasoft DotImage libraries. They have a PDF Viewing component, but it doesn't support the Acrobat style PDF continuous layout, I have to display the pages a page at a time.
I need to build sort of a virtualizing scrollable control which has probably 3 PDFViewers in it, the current frame, and the ones immediately before and after. So my question is - how would I do this?
[I've been doing WPF for the last 3 years, and my WinForms experience has turned to mental mush.]
I need to be able to detect which viewers to open, and which to close. How?
You can do this with a Panel. Set AutoScroll = true and AutoScrollMinSize.Height = pages x control.Height. Implement the Scroll event handler and look at the -AutoScrollPosition.Y property to find out what the user is looking at. Change the Location property of the 3 controls and their Page property as necessary.

Resources