Skip to main content

Microsoft Silverlight

Unanswered Question Modal-Dialogs and MessageBox-Like behaviour.RSS Feed

(0)

Kevmeister
Kevmeister

Member

Member

249 points

119 Posts

Modal-Dialogs and MessageBox-Like behaviour.

Simple problem, so I hope there is a simple answer:

I want to display a message-box. Not a Windows box using Browser.Window.Alert( ), but something within Silverlight itself in order to get pretty visuals (eg. using the Popup class etc).

The problem is not displaying the content but handling the messages. A traditional implementation (eg. WinForms, perhaps even WPF) would result in the MessageBox function running its own message pump, until such time as one of the message-box options has been clicked, and then the result can be returned to the caller.

Is this possible in Silverlight or am I going to have to jump through hoops and do it all asynchronously?

(<whinge>I really dislike obfuscating my code with asynchronous behaviour when I have no good need for it</whinge>).

The WPF resources certainly don't help me: there's no Window class (for Window.ShowDialog), there's no DispatcherFrame (to run an inner message pump), etc.

sladapter
sladapter

All-Star

All-Star

17181 points

3,133 Posts

Re: Modal-Dialogs and MessageBox-Like behaviour.

I wrote a Draggable window object which you can put anything in the window. It has IsModal property you can set. It will basically block the window below until you close the popup window. You might want to take a look and modify it to a message box. It's probably not a read modal dialog but just act like one.

Read this thread:  

 http://silverlight.net/forums/p/12467/41324.aspx#41324

 

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

Kevmeister
Kevmeister

Member

Member

249 points

119 Posts

Re: Modal-Dialogs and MessageBox-Like behaviour.

I shall have a play - thanks.

Kevmeister
Kevmeister

Member

Member

249 points

119 Posts

Re: Modal-Dialogs and MessageBox-Like behaviour.

I've looked at your example code - which I commend you on.

But really it only solves the modality of the UI, not the sequentiality of the procedural code that is usually associated with modal dialogs.

So it seems that, at the moment, a Silverlight (XAML) message-box that stops program execution and awaits a response, just like a real Win32 MessageBox, is not possible, because there is no way I can see to start a nested message pump (or message loop).

Microsoft, if you're listening, I think this is something you should give consideration to if you want to simplify development of LOB applications.

sladapter
sladapter

All-Star

All-Star

17181 points

3,133 Posts

Re: Modal-Dialogs and MessageBox-Like behaviour.

 That's what I mean it's not a read modal dialog. Let's hope in beta 2 we can see something new.

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

Hello, first please note Silverlight is significantly different from Win32. There's no way to get involved with message loop. Even if you can achieve that on Windows, what about Mac?

For your question, if I understand clearly, you have some code like this:

void SomeMethod()

{

//Execute A.

Dialog.ShowDialog();

//Execute B.

}

You want to execute B after the dialog has been closed by the user. Yes, currently Silverlight doesn't have Modal Dialog. So you have to create a Closed event in your dialog. Then in the main page, in SomeMethod, you need to remove Execute B. Instead, handle the Closed event of the Modal Dialog, and Execute B in the event handler. If you have a lot of Modal Dialogs, you can create a code only base dialog. We understand the inconvenience. But unfortunately there's no time for us to build a Window and Dialog system in Silverlight 2. After all, this is not what a common web application needs. Think how many times have you seen such applications on the web. This is something that we're considering for VNext. But I can't give you any details on that at this time. It may or may not be in the next version...

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

Simbalight
Simbalight

Member

Member

245 points

87 Posts

Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

Hi! Using asynchronous behaviour is only one part of the problem. We can work around it as mentioned. The bigger problem in my eyes is to achieve modality. I couldn't find any sample, nor could I figure out how to achieve it. It's simple to avoid mouseclicks. But there's always the possibility to navigate with the keyboard.

Any possibilty to block that? Sth like blocking the entire main container?

sladaper: If you ever find a solution for this please let me know!

 

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Re: Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

I think you can handle the modal dialog's LostFocus event. In the event, you check if the current focused element is inside that dialog. If not, you set the focus back to the original element. You can get the current focused element by querying FocusManager.GetFocusedElement().

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

Kevmeister
Kevmeister

Member

Member

249 points

119 Posts

Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

Yi-Lun Luo - MSFT:
Hello, first please note Silverlight is significantly different from Win32. There's no way to get involved with message loop. Even if you can achieve that on Windows, what about Mac?

Okay, admittedly direct access to the message loop may not be the appropriate solution, but there is no denying that a procedurally-modal dialog-box type behaviour is useful - be it for data entry purposes or message boxes, etc. The current thread of execution should stop and wait for a response from the dialog.

Yes, it can be worked around, but I would argue that platforms that need "too much working around" start to lose their appeal and lose their productivity. 

Yi-Lun Luo - MSFT:
After all, this is not what a common web application needs. Think how many times have you seen such applications on the web.

I don't disagree with the viewpoint, but I think you're not necessarily looking totally in direction where I am. Silverlight has the potential to become, amongst other things, an important tool for building rich line-of-business applications delivered through the browser, partly because it will be easier, perhaps substantially so, than doing so using HTML/AJAX.

An important facet that nearly all large scale LOB apps needs to do is item selection (eg. picking a foreign key), and selection is often handled currently in HTML apps as a "popup". It might be done as a "simulated popup" using a DIV in HTML or it might use a separate Window, but either way there is often call for this kind of mechanism over-and-above a simple embedded drop-list. The popup might need searching features, or there might a tree-navigational structure, or there might be a very large amount of data that needs on-the-fly filtering, all reasonable examples of functionality that is "bread and butter" for a typical LOB application.

True popup windows in HTML are a pain because you have no way to control parent-child modality and/or parent-child lifetime whereas at least with a DIV you can.

Silverlight, when used for LOB applications, is going to have the same functional issues to tackle in some way. There's no denying it can't be done now by breaking up procedural code and dispersing it all over the place to run piecemeal as the outcome of different execution handlers, but that's not an elegant solution in my opinion - it's a hack because the platform doesn't offer a mechanism which is fairly well expected these days of any modern GUI.

So I hope you consider this strongly for vNext and/or final release version 2.

Ciaran Murphy
Ciaran M...

Member

Member

157 points

71 Posts

Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

I agree with you totally Kevmeister. I too would like a simple modal dialog type behaviour. Well if they allow you to pause/resume a thread rather than just send it to sleep it might be possible to create a MsgBox on another thread... maybe. But you can't do that either.

I'm all for clean code... but code needs to be easy to read and navigate too. Requiring EVERYTHING be a response to an event is awkward in the extreme.

I think MS are missing a real market if they neglect the needs of business oriented software.

Dave Relyea
Dave Relyea

Participant

Participant

1084 points

249 Posts

Microsoft

Re: Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

You might want to check this out:

 http://blogs.msdn.com/devdave/archive/2008/06/08/using-popup-to-create-a-dialog-class.aspx

 

michael412
michael412

Member

Member

18 points

6 Posts

Re: Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

I must add my voice to those who are requesting modal dialog capability for Silverlight. I'm having limited success with the LostFocus event. The argument that this is not what a common web application needs is irrelevant. The point of new technologies is not to reinforce current practices but rather to permit new ways of working. The only reason that modal dialog behaviour is not what common web applications need is that to date Microsoft based web applications have not had the ability to use modal dialogs and therefore have been written without them. Anyway, the statement isn't even correct. Plenty of web applications currently do provide this functionality to help users complete fields, etc - they just have to use other ways of doing it. For that matter one could argue that good old drop down lists are modal dialogs, albeit buttonless ones.

We need modal dialogs for our web apps.

CleverCoder
CleverCoder

Member

Member

203 points

157 Posts

Re: Re: Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

If they don't give us the modal dialog, then can you at least provide a mechanism and platform support for building one? A bit of irony here is that the reply I am typing here is being done through a MODAL popup window on an HTML page controlled through javascript and CSS. (And Ajax). I think MS has underestimated the need for modal windows or the ability to disable input to others..

Please consider this for 2.0. At least a viable solution!!

Magikos
Magikos

Member

Member

222 points

144 Posts

Re: Re: Re: Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

I've created a messagebox class and the xmal to look like a standard messagebox with a grid that fills the screen preventing any click throughs to the UI until the the window is dealt wit.

A border control in the center with my message and buttons.  I pass to the class a callback method in the constructor and when the control is closed I call back to that method with a custom set of event args that have the button press results.

 I think you should try something like that. it works perfect for me.

Kevmeister
Kevmeister

Member

Member

249 points

119 Posts

Re: Re: Re: Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

Magikos:
 I think you should try something like that. it works perfect for me.

Yes, so we get UI modality. I would also like procedural modality so I don't have to break up my procedural code into a spaghetti-nightmare mess  because I have to use a call-back function to continue on from a messagebox..

If you are listening Microsoft, it is *annoying* to have to continously work-around limitations in the technology. I live with that as a Beta user but I want Microsoft to listen to its user-base and understand that modal behaviour is wanted.

Dave Relyea
Dave Relyea

Participant

Participant

1084 points

249 Posts

Microsoft

Re: Re: Re: Re: Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

We are listening, but we have finite time and resources. But we plan on having more versions.

sladapter
sladapter

All-Star

All-Star

17181 points

3,133 Posts

Re: Re: Re: Re: Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

Dave,

Do you mean we might have another beta before the final release?  Please do not forget the combobox if you do !

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

Ciaran Murphy
Ciaran M...

Member

Member

157 points

71 Posts

Re: Re: Re: Re: Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

Of course MS are listening... you can see it every day on the forums. Frankly I think the frustration/impatience you're hearing should be both encouraging and congratulatory. To get the level of functionality that is in Silverlight in it's first few releases has been no small feat. It's been done in view of a far more expectant/critical audience than most products ever had to contend with. It took Flash/Flex 10+ years to get where they are today. MS is attemting something far bigger in a far tighter timescale.

I'd love 'proper' modal dialogs too, but as it is, it's a pain, but not a showstopper by any means. Work hard guys!

CleverCoder
CleverCoder

Member

Member

203 points

157 Posts

Re: Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

Dave Relyea:
 

Dave, this has solved my problem beautifully!  This is definitely a good solution for now. It doesn't address the procedural issue, but it gets me past my issue.

Cheers!
- Sean

bhelzer
bhelzer

Member

Member

3 points

3 Posts

Re: Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

Of course I would like a general modal dialogs. But for 2.0 I would be satisified with just a MessageBox.

I just want to put up a simple message when the user goes to a different part of the application: "Your data has changed do you want to save it? Yes - No - Cancel".

And no, I can't do this asynchronously, because if I go on the application will lose it's state. So please don't tell me it's as simple as listening to some event. Since I am already in an event and need to respond to it correctly with user input.

 


 

 

codism
codism

Member

Member

372 points

121 Posts

Re: Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

bhelzer:

I just want to put up a simple message when the user goes to a different part of the application: "Your data has changed do you want to save it? Yes - No - Cancel".

And no, I can't do this asynchronously, because if I go on the application will lose it's state. So please don't tell me it's as simple as listening to some event. Since I am already in an event and need to respond to it correctly with user input.

Basically, you need to redesign your dialog box to accept a callback. The dialog box will call the callback with the user's input. The following code are from our production:

MessageBox.ShowYesNoQuestion("Are you sure you want to delete the buyer?", (r) =>
                {
                    if (r == MessageBoxResult.Yes)
                    {
                        _buyerColl.Remove(bge.Buyer);
                    }
                });

 

CleverCoder
CleverCoder

Member

Member

203 points

157 Posts

Re: Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

 I wouldn't expect too much sympathy in your efforts to find a truly asynchronous solution. Just follow this thread long enough. :) As nice as it would be, it does make a certain amount of sense with respect to how the plugin works. There is no message pump like there is in Win32 / WinForms..  I think you will need to follow the async route to get to where you're trying to go. It would be helpful if there was a solution or helper classes in SL. SOmething like a "Dialoge" base control that has properties for "OkAction" or... "NextActivity"... or .. whatever.  I have a suggestion. Why not incorporate a messageloop like behavior in SL and actually give us all what we want: true modality! :)

hammadmirza
hammadmirza

Member

Member

324 points

107 Posts

Re: Modal-Dialogs and MessageBox-Like behaviour.

Why dont you people try Telerik Rad Controls for Silverlight, it contains a Window Control in 2nd release

Well if you want to make your own, i suggest you somethings:-

the Window Control must have instance of LayoutRoot,
Reason: When a Dialog is shown and you dont want that the UI below that dialog must not be accessed, you need to show a rectangle (full width and height, LayoutRoot.Childern.Add(rectangle) ) with translucent background, just above the UI and below the dialog box(ZIndex)

the Window Control must recieve BrowserResizeEvents,
Reason: If a Dialog is currently active, and user resizes the browser, you need to resize that translucent rectangle to new dimensions, or you may want to center align the window.

I did all this in Silverlight 1.1, so any more questions you can ask.

http://hammadmirza.wordpress.com
http://www.idraw.co.cc
(IF YOUR PROBLEM HAS BEEN ANSWERED OR SOLVED, MARK IT AS ANSWER)

grava
grava

Member

Member

87 points

18 Posts

Re: Modal-Dialogs and MessageBox-Like behaviour.

 Only way to Resync APM model of Silverlight is plumbing SL with a "Custom" message loop.

the method :

public voi a() 

{

f1();

modal1.ShowModal();

f2();

}

have to be rewritten in something like:

public void a() 

{

actionQueue.Start();

actionQueue.Execute(new Action(a));

actionQueue.Execute(new Action(ShowDialog));

actionQueue.Execute(new Action(b));

actionQueue.End();

}

 

Try to think at ActionQueue as a Queue of System.Action<T> (or Func) and at the end() statement start the dequeuing of the actions Synchronously ... the only Great problem is that you have to Resync with the RootLayout.Dispatcher for refreshing the UI.

We're writing an article about the resync problem which involves, for instance, a call to a WCF service, a Prompt and another call to WCF, in which we don't use APM (async programming model with "OnComplete" delegates), but plain C# Code.

 Stay tuned, we've implemented everything and it seems it's ok ... we're investigating in more complex cases if we could run in starvation, race conditions or something else that ... well, it's the problem that pushed MS to remove sync methods ... Blocks our main UI Thread .

GG

Gianluca Gravina

jemiller
jemiller

Member

Member

445 points

237 Posts

Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

 

Yi-Lun Luo - MSFT:

Think how many times have you seen such applications on the web. This is something that we're considering for VNext. But I can't give you any details on that at this time. It may or may not be in the next version...

I've seen it a lot in the Flex apps that I've developed...


Jamie H
Jamie H

Member

Member

33 points

40 Posts

Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

I also agree, having modal dialog functionality is pretty cirtical for app development.  I work for a web design company and all of our "web 2.0" designs are includuing modal dialogs that we have to hack up with html divs that cover the entire screen.  I wanted to tell everyone we could do this much easier in Silverlight, but without modal dialog support, it is as much of a hack in Silverlight as it is in HTML/javascript right now.

 

 

jemiller
jemiller

Member

Member

445 points

237 Posts

Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

Hi all,

 I created a Connect Feedback request for modal dialog box-like behavior for Silverlight at the following URL. If you agree with me, please rate my feedback. Thanks.

 https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=368862

lingbing
lingbing

Contributor

Contributor

2249 points

406 Posts

Re: Modal-Dialogs and MessageBox-Like behaviour.

I think I must say something about this issue. I have read Dave's blog and known his idea about how to solve this problem. Yes, it works, just as we want, however, when we design a usercontrol, we sould consider both its activity and its presentation. Simply if we make a canvas with a transparent backgroud, the user could not click through thd popup, and if we add a close event and handle it we can make some code run after the event fires, but the problem is that when the users download our application, they will find the Behaviour is not like a MessageBox or Modal-Dialog, even they cannot click through, even all functions work well, If you have a look at OpenFileDialog in silverlight, it is completely windows-like, its behaviour is as same as both win32 and wpf, so that when users use it, they will find that they are using an application just like at desktop but not at a browser. I think that is why we want MS to create a Modal-Dialog and we can use ShowDialog method to show it to user just like desktop form applications.

I don't know if you agree with me at this point, however, we must acknowledge that some common controls are necessary, such as ComboBox (Dropdown), Treeview, RichTextBox...and so on. I know MS silverlight team is busy with much work, hope you work well!

Ling Bing
Bei Jing University of Aeronautics and Astronautics
Bei Jing, China

lepipele
lepipele

Member

Member

44 points

22 Posts

Re: Modal-Dialogs and MessageBox-Like behaviour.

Here is best modal dialog control I've found:
http://www.codeproject.com/KB/silverlight/slmodal.aspx

ygoldman
ygoldman

Member

Member

4 points

2 Posts

Re: Modal-Dialogs and MessageBox-Like behaviour.

I've put together a generic framework for creating modal popups - article is here: http://blog.yuriy.org/2009/01/building-modal-popup-framework-with.html.  It

Goals of the Framework:

  1. Allow any Control to be "popped up" in modal and non-modal modes
  2. Construct a framework that is modular and made up of discrete, reusable components
  3. Properly hide implementation details and expose a simple api for developers to utilize.
  4. Reduce the amount of customization to the framework required by front-end developers.

davides77
davides77

Member

Member

3 points

19 Posts

Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

 Hi guys,

I tried the modal dialog and all works fine but...

but I put a datagrid in the modal dialog, all works fine but when I go over the header of the colums all the silverlight application disappear!!!

why?????

tnx very much!!!

kobruleht
kobruleht

Member

Member

141 points

525 Posts

Re: Re: Modal-Dialogs and MessageBox-Like behaviour.

Silverlight modal messagebox is like standard silverlight control, it routes click event to sl button if its button is placed in the same location in screen as sl button.

We can hopefully create our modal control and after it show hidden messagebox to create modal loop. After clicking we can release modal messagebox.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities