Currently I am working on a xaml page with several buttons that are going to link to other xaml pages, but I cannot figure out how to navigate from one xaml page to another. This is what I currently have.
Private Sub GoTools(sender As Object, e As MouseButtonEventArgs)
MainFrame.Navigate(New Uri("Tools.xaml"))
End Sub
This is what I have seen on a lot of websites so far but this does not work, how should I change this so that when I click a Tools button it brings me to the Tools page?
(Quotes have been changed)
When I run the program and click the button I get this error
An unhandled exception of type 'System.UriFormatException' occurred in System.dll
Additional information: Invalid URI: The format of the URI could not be determined.`
How about you do it this way:
Private Sub GoTools(sender As Object, e As MouseButtonEventArgs)
MainFrame.Navigate(New Tool)
End Sub
I am not familiar with VB, but you have to create an instance of your Tool page. In case you already have one just navigate to it.
Related
I am trying to build a basic front-end to link information together that would be accessible by clicking a text box (or a button) on the front page of the GUI. Basically, I have a number of text boxes for the different "functions" I want to show information on.
How do I make it so that on click, that box will open up a new window that I've already designeD? Within the solution (WPApplication,) I have all of the .xaml's set up (that are the seperate windows) in the solution already- I just want to call the on-click to open them. I figured it'd just be Show('Window Name') after private/as/handles, but it gives me an expression. Here's what I have:
Private Sub PO_info_MouseDown(Sendar As Object, e As MouseButtonEventArgs) Handles PO_Info.Mousedown
Show('PO Information')
End Sub
End Class
To flesh out my comment, the new window objects that you created are classes, you need to create an instance of the class before the Show Method will work. Lets assume that your PO Information forms class is POInfo you would need to do something like this.
POInfo POInformation = new POInfo;
POinformation.Show(); //This is where your show method is
Since your code looks like vb.net it would look like this in VB
Dim POInformation as New PoInfo
POInformation.Show()
First some explanation:
I am attempting to make (what should be) a simple offline "character generator" for a game I am working on. I am using VB for this and I am still a beginner. I have created a WinForms application in VS 2012 and created a local database object to hold various data. Within the database I have a 'Players' table to hold all the data. I have also added a BindingNavigator to the form, yet I removed all but the add and delete buttons as navigation is controlled by a List control which is bound to the PlayersBindingSource. I also added a save button to the BindingNavigator.
I manually populated the 'Players' table with two example entries to work with and, when the form loads, the listBox displays the two entries by their 'Player Name' field correctly. When one is selected all the controls representing each field change accordingly. If I change any values and hit the save button, it seems to work with the code I'm using.
Now the problems:
When the add button is pressed, it makes a new entry in the ListBox, yet none of the default values specified are showing up. If I edit this entry and then hit save it seems to update fine. However, if I make any other changes to any of the entries and try to save, it throws an exception.
When the delete button is pressed, the entry disappears from the list as expected, but again, if I try to save, I get an exception.
here is the code that is in my form thus far (not much):
Public Class frmMain
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.PlayersTableAdapter.Fill(Me.DatPlayerDataSet.Players)
End Sub
Private Sub SaveToolStripButton_Click(sender As Object, e As EventArgs) Handles SaveToolStripButton.Click
Me.Validate()
Me.PlayersBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.DatPlayerDataSet)
End Sub
End Class
Also, if I look at the data contained in the 'Players' table, the two example entries remain unchanged, and no additional entries are added, so I don't think the edits were never actually committed to the table.
If anyone can help me with this, or could even simply provide a link to some tutorials that would help me, I would be highly appreciative. I have browsed this site, and microsofts msdn library, searching for information about data binding and navigation, yet I couldn't seem to find anything that helped.
You want do one more think in "btnNewPlayer_Click" sub after insert row, clear the list and re load the list items or call the function which you are using to fill the list items.
Try refreshing the page, the list might get updated.
Think about a WPF program that has 2 pages which you navigate between. (Upload and Crop)
In the first page, you load an image using a button, select the image, and your image appears in the WPF Image control. Then, you press the "Crop" button. That sends the navigation to the second page, which you can crop the image.
Then, you crop the image in the second page. Then you press "next". Next button must redirect you to the first page, but wait a minute, the image you loaded no longer exist in the page. Because it's a new page.
Dim CropPage As New Crop(Crop_Bmp, Crop_BmpSource)
Me.NavigationService.Navigate(CropPage)
You may think it's okay. Because we pass the parameters and we can refill the WPF Image controls using that parameters. But, there is actually 8 upload panels in the page 1. So, other ones are important.
Or think about another method I found. Instead of using a new page instance, navigate back that you used.
Upload.Crop_Bmp = Crop_Bmp
Upload.Crop_BmpSource = Crop_BmpSource
Me.NavigationService.GoBack()
Upload.Crop()
But in the second one, it throws errors.
"Reference to a non-shared member requires an object reference."
Then, back to the Upload page, I made the variables and functions "Shared". But then, more problems come up. Because you cannot edit the local variables unless you also make them Shared. So, all of the variables and functions need to be "Shared".
I'm searching about a solution for a few days and I could not get rid of them. What method should I use? Redirecting back, or opening a new instance?
In old-type applications, it was very easy. All was that:
Form1.Crop_Bmp = Crop_Bmp
Me.Hide()
Form1.Crop()
And it was working perfectly. Because the forms were not instances like WPF pages. That's the reason I find WPF quite weird.
I found it a way to do this. When navigating to the Crop page, I sent the Upload page as a parameter to Crop Page.
Dim CropPage As New Crop(Crop_Bmp, Crop_BmpSource, Me)
Me.NavigationService.Navigate(CropPage)
Then, in Crop:
Public Sub New(ByVal Crop_Bitmap_ As Bitmap, ByVal Crop_BitmapSource_ As BitmapSource, ByVal pg As Upload)
' This call is required by the designer.
InitializeComponent()
UploadPage = pg
Then, in the Crop page, I accessed that parameter to modify its elements. For example:
Me.NavigationService.Navigate(UploadPage)
UploadPage.Crop()
This sounds like a bad use-case for the Pages metaphor. Pages are for loosely coupled peer screens (E.G. A separate page for each department), but you are using them in a tightly coupled parent-child relationship. (The "Crop" page is the child of the "Upload" page) For what you are doing, launching the crop screen as modal dialog might be more fitting.
If you want to keep everything in the same window, you can keep both functions in the same window, and toggle their visibility as needed.
I have a Silverlight 5 OOB application (with Elevated Permissions) that's just been deployed to a number of our users.
Some of these users are reporting that prints are coming out blank or very faint.
These printers do print Word documents correctly and I am unable to reproduce the problem on my own printers.
All users are on Windows XP SP3 32 bit, and I am developing on Win7 64 bit.
As anyone seen this issue before? Or any idea what could be causing this?
Help much appreciated.
Many Thanks,
Andrew
I Should Got Solution May Be useFull To You.............................
First i created a new PrintDocument, and hooked up some handlers for its PrintPage event.
mobjPrintDocument = New PrintDocument
RemoveHandler mobjPrintDocument.PrintPage, AddressOf Print_Report
AddHandler mobjPrintDocument.PrintPage, AddressOf Print_Report
Then we can call the PrintBitmap function on the PrintDocument whenever you want to print. Here I am doing it when the user clicks the Print button.
Private Sub xbtnPrint_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
mintPageIndex = 0
mobjPrintDocument.PrintBitmap(FileName)
End Sub
Now comes the important part. We can hijack the content targeted by hooking into the PrintPage event (as handled above). I can set the e.PageVisual to any visual xaml element and the PrintBitmap will handle it. Here I use the GetPages function and loop through to make sure I print each page (a pdfviewer element). However, you can point it to any visual element like I said.
Private Sub Print_Report(sender As System.Object, e As PrintPageEventArgs)
e.PageVisual = xobjReportViewer.GetPages(mintPageIndex)
mintPageIndex += 1
e.HasMorePages = mintPageIndex < xobjReportViewer.GetPages.Count
End Sub
The e.HasMorePages allows you to force the firing of this event until you are finished.
Hope this is helpful to someone. With Silverlight 5 and the Post-Script printer support, alot of printers that have a PostScript emulator may not be compatible, but will also not default to bitmap printing. This workaround fixes that, making printing a little bit more stable in a LOB type application.
I've come across a strange scenario where a frame refuses to refresh its content.
I can kinda understand what's happening but the solution is not coming to me.
I have a page that has a frame (Frame1) and several buttons. When I click on a button a page is loaded into the frame. This works perfectly in most situations.
Private Sub btnIncidents_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnIncidents.Click
Frame1.Source = New System.Uri("/Incident/Incidents.xaml", UriKind.Relative)
End Sub
However, I have a situation where I need to select the button that was previously clicked to effectively do a Refresh on the Uri. The problem is it simply does nothing because the Uri hasn't changed. That makes sense but it's not what I want, I need to call it again.
My first solution was to introduce Frame1.Refresh which initially did the trick. But once a page was Refreshed, none of the Buttons could load a different page.
It was as if by calling Frame1.Refresh I'd broken the Frames ability to navigate to other pages.
My second idea was to set the Frame source to Nothing (Null) and then set the source to the URI but that didn't work either. ie Frame1.Source = Nothing
Has anyone else come across this or maybe have some suggestions? I just need to Refresh/Reload the Frames page without breaking the Frame!
I had the similar problem - with html though. Resolved it with
frame.NavigationService.Refresh();
apparently will clear navigation history, but in my case I do not really care.
Got the answer from http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/8fc6bd83-2803-4820-a22b-d4d87638c4e2