I'm developing a Silverlight 4 RIA application. There is a DataGrid storing data and two buttons: add a new item and remove an item. After creating a new item for the second time the application freezes like this - I'll explain the strange behaviour below.
The scenario of creating a new item looks like this:
After clicking, the child window appears. The reference to the domain data source used on the parrent page is being
passed to the child window in the constructor.
The user chooses a file.
The file is send to a web service. In response the web service returns some data from that file.
A new data object is being created and inserted to domain data source.
The child window causes the entire application to freeze only when it's called twice, but the first call requires object creation. I can open and close the child window repeatedly and everything will work fine until a sequence of: open.create -> open.close / open.create occurs. I tried to trace all exceptions with VS tool (alt ctrl e) but there are none.
A breakpoint on
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
does not show anything either. Any ideas?
Page code.
Child window code
Remove the following and everything will be fine.
private void ChildWindow_Closed(object sender, EventArgs e)
{
this.DialogResult = false;
}
And to evaluate a bit more, ChildWindow_Closed is the outcome of setting the DialogResult at the first place.
By re setting it unexpected things happen.
I did a bit more research after you helped me with this issue. Seems its a SL4 bug.
This should also help. Topic about this on SL forums.
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
Application.Current.RootVisual.SetValue(Control.IsEnabledProperty, true);
}
Related
I'm studying to become a developer; as a formative project, I'm working on a desktop app to help me organize local amateur chess tournaments with MAUI. Basically, I want to be able to open multiple windows during the same execution, so that I can run various parallel tournaments on the same machine.
On the MainPage I placed a button that creates a new window that displays the NewTournamentPage
private void NewTournamentButton_Clicked(object sender, EventArgs e)
{
Application.Current.OpenWindow(new Window()
{
Page = new NewTournamentPage()
}) ;
}
in the NewTournamentPage I placed a button to add a new player to the tournament, and I want the window to freeze until the user inserts the player name, but without blocking the execution of the other windows. DisplayPromptAsync seems to be exactly what I'm looking for, so I did this:
public async void AddNewPlayer_Clicked(object sender, EventArgs e)
{
string newPlayerName = await this.DisplayPromptAsync("Add new Player", "Name:");
//code to add player to tournament
...
}
When I execute and click the NewTournamentButton multiple times, the windows are created with no problems, and they all work independently from each other, but when I press the AddNewPlayer button, the popup pops on the MainPage window, not on the one calling the method, and it takes and saves the input in newPlayerName; then, the same thing happens on all secondary windows, in order of creation, without updating newPlayerName. What is happening here? What am I missing?
Yes, it is just the case as you said. And I have created a new issue about this problem on github.
You can follow it up here: https://github.com/dotnet/maui/issues/7650.
Thanks for your feedback and support for maui very much.
I'm trying to create two Windows Forms with buttons in order to linking them to each other, using this code:
private void cmdInformation_Click(object sender, EventArgs e)
{
frmInformation information = new frmInformation();
information.Show();
}
(It's the same way for the second form)
When using this code you will have multiple windows of same form if you keep clicking the buttons. What can I do to stop this?
The best solution will be linking forms together without creating a new one, but I don't know any other way than one above.
Tested Hide() but it just hides the multiple windows and program remain open even if you close last shown window.
Tried Close() but when it close the main form whole program is ended.
Use a dialog.
information.ShowDialog();
You can also read up on dialog results and get responses from your form if that is needed.
Move the creation of the opposing form outside of the click event.
frmInformation information = new frmInformation();
private void cmdInformation_Click(object sender, EventArgs e)
{
information.Show();
}
This will re-display the same form over and over maintaining any data even when the user closes it.
An option would be to create a FormFactory that keeps track of the instances, this way if the form doesn't exist you can create a new instance and show it. If the form exists you can just show the current instance.
I have a program written in c# that contains a listbox with an observable collection. I want a balloon to pop-up for the user (in the system tray) when the collection has an item added. I have a class that contains a method for notifying the listbox when an item is added (see below):
void OnFileCreated(object sender, FileSystemEventArgs e)
{
if (!base.Dispatcher.CheckAccess())
{
base.Dispatcher.BeginInvoke(
DispatcherPriority.Normal,
(FileSystemEventHandler)OnFileCreated,
sender, e);
}
else
{
// Ignore new directories.
if (File.Exists(e.FullPath))
{
Debug.WriteLine("File Created: " + e.FullPath);
_files.Add(new ObservableFileInfo(e.FullPath));
//Alert users to new request
string title = "Access Request";
string text = "A new access request has been submitted";
//show balloon with built-in icon
tbi.ShowBalloonTip(title, text, BalloonIcon.Error);
}
}
}
The code works exactly as intended apart from the fact that the balloon will only show if I create a new instance of the balloon within the OnFileCreated method (not seen above as I took the code out). For reference, I am using the system tray icon .dll from the following project: http://www.codeproject.com/Articles/36468/WPF-NotifyIcon?fid=1540774&select=4624878&fr=51#xx0xx
My issue is that I already have a system tray icon initiated in the MainWindow class, but I cannot call on it to show a balloon from my OnFileCreated method. I am not sure how I can "share" this information across classes.
If anyone has any ideas that would be great.
I ended up using FindResource to locate the resource defined in the xaml resource document. This was specified in the project code I was referencing to, however FindResource was not working by itself, I needed to add App.Current:
notifyIcon = (TaskbarIcon)App.Current.FindResource("NotifyIcon");
notifyIcon.ShowBalloonTip(title, text, BalloonIcon.Error);
I have created a little Win Form App in C# and added the WebBrowser component to it. What i am trying to achieve is a little app that can load a local html page from a file which has "custom" protocols in it and can of course also navigate to a web address.
For example i would have entry as follows in my webpage
'Close Company</TD></TR>' which would open a task in a program.
The way i tried to achieve this was via the Navigating event as shown below
private void webBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
if ((webBrowser.StatusText.Contains("Special")))
{
//For some reason the stop doesn't do much it still tries to proceed to special:123
//diplaying can not load page..
webBrowser.Stop();
//Launch program here.
MessageBox.Show("Special Command Found");
}
}
Problem is that it still navigates and says it can't find of course the page.
I swapped Stop with GoBack which for some reason has the same issue the first time i run it and when i then select backward in the browser it works from thereon.
I also tried navigated and use of GoBack, besides having a flashing in the app from going back the event does not fire again after the first time anymore.
Has anyone any ideas how to solve this or what i am doing wrong here ?
Instead of using WebBrowser.Stop();
just set e.cancel = true;
I have an application for Windows 8 with a page (Frame) for displaying a list of items and a page for downloading & displaying the items details. I am also using MVVM Light for sending notifications.
Application use goes something like this:
Open Main Page
Navigate to List Page
Frame.Navigate(typeof(MyPage));
Choose Item
//Complete logic
Frame.GoBack();
Back on Main Page, I start downloading the file in the view model, I send ONE NotificationMessage saying BeginDownloadFile and after it is downloaded ONE NotificationMessage saying EndDownloadFile.
The first time I do steps 2,3, & 4 my NotificationReceived method is hit once, the second twice and so forth.
private async void NotificationMessageReceived(NotificationMessage msg)
{
if (msg.Notification == Notifications.BeginDownloadFile)
{
FileDownloadPopup.IsOpen = true;
}
else if (msg.Notification == Notifications.EndDownloadFile)
{
FileDownloadPopup.IsOpen = false;
}
}
Additional information: I only have one FileDownloadPopup, yet each time, an additional popup is shown each time the NotificationMessageReceived method is called.
My only conclusion is that between navigating forwards and backwards in my app, there are multiple MainPages being created and never closed. This results in many NotificationsMessageReceived methods just waiting for a notification to come their way so they can show their popup.
I have two questions:
1. Does this sound like normal behaviour for a Windows 8 app?
2. How can I close all instances of the MainPage or return to the previous instance without creating a new instance?
Please let me know if I have missed something important out before marking my question down.
This sounds normal to me. The default navigation behaviour in Windows 8 is to create a new page instance each time you navigate to a new page, regardless of whether this is forward or back navigation.
Try setting the NavigatinCacheMode on MainPage to Required. See the MSDN documentation for details of how page caching works.
It sounds like you are registering eventhandlers in the page and then not removing them. Each time you navigate to the page again the handler is being added again in addition to the one you previously added. Try to add your event handler in OnNavigatedTo, and make sure you unregister it in OnNavigatedFrom.
protected override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
MyEvent.OnDownloadRequest += MyLocalDOwnloadHandler; // add the handler
}
protected override void OnNavigatedFrom(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
MyEvent.OnDownloadRequest -= MyLocalDOwnloadHandler; // remove the handler
}