updating UI in windows phone 7 - silverlight

In method that is working in the background, i have two important lines :
createPopup();
MessageBox.Show(sth);
more lines
more lines
createPopup() just creates a popup, adds a grid as a child and shows popup.
My question is, why first shows up messageBox, then shows up Popup, which appears after all lines in this method done ? How could I make this popup to show before all lines in this method will be done ?

All the UI changes are normally queued up and will be shown at once on the screen.
And this does not include MessageBox. So it shows up immediately and prevents the execution, until user clicks on Ok. Hence eventhough your popUP is first executed, it will be shown in the UI only after the MessageBox.
For your problem, Try placing your MessageBox.Show(something) in a separate thread.
createPopup();
Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("some message");
});
more lines
more lines
Give it a try. I am not sure whether it solves your problem or not as I dnt know the code in createPopUp() method.

Creating the pop-up, does not actually draw it on the screen until the Layout event. If you want to ensure that the pop-up has been drawn before you display the pop-up, attach an event handler to the pop-up's LayoutUpdated event and display the message box from within that event handler. Be sure to detach the event handler as well or you will see multiple message boxes.
public InitPage()
{
Popup popup = new Popup();
popup.LayoutUpdated += popup_LayoutUpdated;
LayoutRoot.Controls.Add(popup);
}
void popup_LayoutUpdated(object sender, object e)
{
popup_LayoutUpdated -= popup_LayoutUpdated;
MessageBox.Show("hello");
}

Related

Combobox gets closed on MessageBox closure ZK

I'm using ZK CE-9.0.0.
I have a combobox which I need to open programmatically, on click of OK button of the Messagebox. Hence I have implemented a Listener for the click event of the OK button. Inside the click event, I'm opening the combobox by using the following code:
EventListener<Messagebox.ClickEvent> clickListener = new EventListener<Messagebox.ClickEvent>() {
#Override
public void onEvent(ClickEvent event) throws Exception {
mycombo.open();
}
};
Messagebox.Button[] buttons = new Messagebox.Button[] {Messagebox.Button.OK};
Messagebox.show("Hi btn", buttons, clickListener);
Now the problem that I'm facing is, the combobox opens for half a second. It then immediately gets closed automatically.
As per my understanding, it's because of the Messagebox. Once the execution of the click event is completed, the Messagebox is closed & it causes the combobox also to be closed.
Please have a look at this fiddler for better understanding. Please select the ZK version to be 9.0.0 before running it.
Can anyone help me with this please?
Thanks,
RAS
You are correct that the main issue comes from the button retrieving focus after the animation of the combobox.
The focus is given back to the button by the closed messagebox
Since the combobox loose focus, the combo popup is also closed.
A clean way to handle this would be to use an echo event to wait for the messagebox to be actually closed before sending the open action to the combobox.
See this fiddle:
https://zkfiddle.org/sample/1rkm5d/6-Combobox-gets-closed-on-MessageBox-close#source-2

getting textbox focus after messagebox in chrome browser

when I show a messagebox and after it make a textbox focused It dose not work in chrome browser but in IE Firefox and others I works, I googled it but without result, can sb help?
MessageBox.Show("", "", MessageBoxButton.OK);
Textbox.Focus();
return;
We had a similar problem. We had to use the Dispatcher to send the focus request asynchronously.
textbox.Dispatcher.BeginInvoke(() => textbox.Focus());
We've also seen issues with certain Silverlight runtimes disabling the parent screen when a dialog box is opened, or rather not re-enabling the parent once the child dialog closes. The following line of code forces the main screen to be enabled. It's possible the textbox isn't receiving focus because the entire screen is actually in a disabled state.
Application.Current.RootVisual.SetValue(Control.IsEnabledProperty, true);

WPF Tab_selectionChanged

I have this strange issue I am facing currently.
I have created an WPF application based on WPF page navigation. I have few button and depending on the button click the the user is navigated to respective WPF page.
In these WPF pages I have Tab controls and have used selectionchanged event handler to perform some task.
Now to the issue,
When I try to go a particular page, the selectionchanged event is also executed even before the page is loaded completely, I have tried to use the windows.loaded (based on the answer provided to my previous question - here) - I have no luck.
[I am using WPF Navigation framework]
Somehow the selectionchanged event is executing twice.
How do I stop this from happening?
I think you should check SelectionChange.AddedItems and SelectionChange.RemovedItems to find the difference between these to firings. I guess that when you select a page, SelectionChange.RemovedItems==0 while when you click on a tabItem to select it, SelectionChange.RemovedItems==1. if so just write:
if (SelectionChange.RemovedItems==0)
return;
Edit1: Please see the first comment.
Edit 2
void tablcontrol_SelectionChange(object sender, SelectionChangedEventArgs e)
{
if (e.RemovedItems.Count == 0)
{
// I guess this is the event that happens when a page is selected
// in this case just a TabItem is added to the selection
// and nothing is removed, so do nothing
return;
}
// if you are here, it means that this is another selection changed event
// so Perform those tasks that you mentioned in your question
}

Silverlight fire an event then fire another even a second later

Is there a way to do something like this?
Background:
I have a button click. When the button is clicked I try to show a "loading" message, run a bunch of code that does some UI work and then dismiss the "loading" message. It takes anywhere from a few seconds to 20 seconds usually. At the moment the loading message doesn't show at all and the UI freezes until the code in my button click is done.
I've read about Background Worker and dispatcher, but haven't been able to get it to work. I'm not sure if it's because the code in the button click calls all sorts of other code (including 3rd party stuff), but I haven't been able to get it to run correctly. It all still works, but it still freezes the UI and the loading message doesn't appear.
So, I am wondering if there is another way around this. Is it possible to set it up so that on the button click I only show the loading message and then a second or so later fire another event that executes my long running process? That way the UI will still freeze for some seconds, but at least it will show a "loading" message.
You should be able to do this with a Dispatcher.BeginInvoke call.
private void ButtonClick(object sender, EventArgs e)
{
ShowMyLoadingMessage(); // your code, not sure what it is
Dispatcher.BeginInvoke(() =>
{
CallMyLongRunningCode(); // again, not sure what this is
HideMyLoadingMessage();
}
}
I don't believe this is the best solution since it is running on the UI thread, but it should do what you are asking.
What is the long running code doing that takes 20 seconds?

When Modal Dialog is shown in WPF and a user clicks on the parent window, make the modal dialog flash, blink or shake

New Thought, Maybe I am looking at this totally incorrectly. So Here is exactly what I am trying to do in case there is another option I am not aware of.
I have a WPF app, the main window shows a smaller dialog window using ShowDialog(), when a user clicks on the parent window that showed the dialog, I need to make the dialog window, flash, shake or blink.
AresAvatar posted a link that looks like it might be able to use, but is there another option I am not aware of?
My original Question.
Mouse click event when Modal window's parent is clicked in WPF app?
I have a wpf app that shows a modal window using ShowDialog().
I would like to fire an event when the user tries to click the parent window that is now disabled.
Is it possible on the parent to receive a click event when it has shown a modal window?
When I attempted this using an interaction trigger, the events never fired on parent window.
Otherwise, what suggestions / options are there.
Thanks
No WPF events are sent under these conditions. The only Windows message I can see that gets sent is WM_WINDOWPOSCHANGING. You could check for that message, and check if the window was disabled when it occurred. Here's a good article on checking WM_WINDOWPOSCHANGING.
Edit: that link seems to be dead. Here's an example on StackOverflow of checking window messages.
I know this is an old question but I'll post my solution in case any one needs it.
Set the dialog.owner prior to calling ShowDialog().
var dialog = new DialogWindow();
dialog.owner = MainWindow;
dialog.ShowDialog();
The result is that clicking on the main window, brings the dialog window to the front and makes the dialog window flash.

Resources