Pop-up [original] Silverlight - the show

background

Years later to the internship, the first week there is no project, there is nothing to do, at this time there is a senior and I said, they have developed a system that is based on Silverlight, and uses pop-up window where there is a lot of problem, so if I may, I want to make a pop-up window function, and its children can be customized any control.
I am glad only a few days into the company will be able to have such a task, every time I go to different internship, always been "entrusted with the task in a very short time (of course, more of my own narcissism) "to carry out R & D infrastructure available, very grateful to have been from the beginning sophomore so trust the companies and see me, I think you can only go all out in this environment ......
in short take over this task the situation is like this, then in the end how far I have knowledge of Silverlight do? The answer is zero. Those who know me know that I am very, very no level of art, and therefore almost all the front desk for technology development are at arm's length, of which Silverlight is so novel that I hope born of confidence.
But things have been so, joined the company can not say I would not do, so he went to bite the bullet, the end result is this:
First, a half-day basic model Silverlight hold grip, including understanding of grammar Xaml as DependencyProperty, AttachedProeprty and other basic familiarity with the relevant API, as for the concept of control tree like, Winform and Webform is basically the same model, so familiar and relatively quickly
followed by a half a day, toss out a pop-up window prototype looks really quite comfortable, then close the pop-up window, two windows have been closed again, particularly big problem did not occur
then, within five minutes and found that things are not perfect, there are a lot of problem, so architecturally completely knocked down once before work, it is clear that my implementation is based on a design error, and therefore requires that the entire model is redesigned and once again achieved
through another half-day effort, finally a more idealized design, and complete implementation of this version

Our choice

For such a pop-up window function, we Silverlight is a wide selection of, before introducing my work, let's look at the advantages and disadvantages of various selection

Select 1: MessageBox

Silverlight is really a MesasgeBox of, and Winform in the same call to MessageBox.Show, but there are also many problems, of course, before the one hand, we must first look to good
advantage: MessageBox is synchronized that after calling the Show method can directly obtain the return value, synchronous programming has a very big advantage compared to asynchronous programming on simplicity, therefore indeed be a good choice as a
drawback: JS framework should know why each out of a MessageBox it, this is because the alert too ugly thing, and now we are facing a more brilliant Silverlight applications, pleasing enjoying the same time, we going to see from time to time and a pop-up alert window is exactly the same guy disappeared?

Select 2: Popup

Popup is a Silverlight Control base class library provides functions can be done directly pop
Advantages: simple operation, you can use Xaml presentation, encapsulates the pop-up menu, the style can be customized, as a very powerful official solution
Cons: It seniors He said that when the popup contains complex controls like DataGrid, there will appear Bug, this is I need to do a completely out of the main window pops up ......

I work -PopupBox

I can not call MessageBox, because the base class library have this thing
I have no idea known as Popup, because the base class library also have this thing
I do not want to own work on the basis of class libraries and has appeared at the beginning of the conflict It requires the caller must use the global namespace reference, but do not want to borrow the official name gives the feeling of confusion
as a showcase of works, take a look at how this thing is used. In fact this is not a control, but a class, so you can not use the Xaml declared that he, the reasons for making such a decision, first, I just mastery Xaml, are not familiar with, so if you want to do using Xaml declared, may still not see the shadow of this guy, and secondly because pop-ups are often used to dynamically determine its content through programming and control whether the pop-up, so will it be used as a class will not have too much trouble
for our the pop-up window, you first need to get the object called PopupService, which is in charge of all things pop, you can not explicitly construct a PopupService by new, and this object must be obtained through the factory way

PopupService service = PopupService.GetServiceFor(LayoutRoot);

Then, we can use a variety of heavy-duty, to obtain an instance of the pop-up window from PopupService by calling GetBoxPage, its first parameter is displayed in a pop-up window controls, type FrameworkElement, the second parameter is the title of the window, the latter parameter controls whether such a drag, a close icon etc. is displayed, the following call

BoxPage Box = service.GetBoxPage ( 
new new MyControl (), control // display
Title.Text, // title
to true , // whether you can drag
to true // whether to display the Close icon
);

You can add special effects when to appear and disappear BoxPage, existing support special effects to fade, zoom, and no special effects, of course, it can very easily be extended from the design

box.Effect = Effect.Fade(box);

BoxPage has ShowComplete and CloseComplete event, you can do some operations by registering these events

box.ShowComplete += new EventHandler(Box_ShowComplete);
box.CloseComplete += new EventHandler(Box_CloseComplete);

Finally, call the Show pop-up method, of course, you can call ShowAsModal method to pop up a modal window, the window is in the so-called mode pop-up will cover all of the following controls

box.Show();
box.ShowAsModal();

If you think this is fairly simple to use, then I think I've won half the battle, of course, we still have another control, you can get a message dialog by calling GetMessagePage PopupService method, which is used to display only a not as a simple custom message box contents, put this in the first two pictures show what effect
the show before, I would like to declare three, my art is not generally poor, so the dialog style is very ugly, please give me time to improve the style, thank you ......

Pop-up display

Is a pop-up window on the left, the right is the message window

This version of improvement compared to the previous version

Of course, everyone is on a version not seen and never will see, but as responsible for their own, I still look at this version of the record improvements, and between this function should also be able to glimpse this pop-up window
1. solving problems plurality of mask layer repeat pop-up window, the pop-up window will now share a plurality of mask layer
in the case 2. the plurality of solution in a popup window modal dialog box, modal dialog box will not close this problem canceling mode mask layer
under 3. solve multiple pop-up window, click the window background to place the top issues

Improve subsequent versions will appear

Perhaps the next version, maybe next n versions, but these improvements have been included in the plan, one day they will get to realize
the language of the 1. The multi-country, mainly the button text
2. Provide more style customization
3. storage optimization PopupService will have been useless PopupService (i.e., no longer manages any pop-up window) promptly removed from cache
4.BoxPage Border plus
5. in this pop-up window are intermediate mask layer, can be improved to a specified window when the eject position relative to the mask layer
6. If the position of the pop-up window has other windows, then the window offset amount to ensure that the original will not completely block the window
7. when the pop-up window can be dragged out of its range of the mask layer, the mask layer may preferably control the size of the pop-up window and allowed free to move, so that the movable range of the pop-up window can be controlled within a region of

Known Bug

Of course, I'm just a rookie, there must be something out of the question, this is a problem found so far, I hope you provide a lot of Bug
1. When the picture is loaded in BoxPage using relative paths will cause a relative path library reading pictures, images generated read error, I do not know how to read the current set up to run the project as a relative path
similar parts the same as in the code 2.MessagePage and BoxPage still exist, can not be completely separated from the abstract, it is necessary to consider optimal design
3.MessagePage in when the content is a number with no spaces in the English string, can cause problems last newline
4. use fade effects, because the time window disappears, so many times you can click on the different buttons on the MessagePage, but results last click of the button prevail, should be amended to follow button clicks are invalid
5. countless unknown problems and BUG ......

Introduces the design and implementation

I write to you when I suddenly found myself a little tired, although this is the most important element, but rarely come to Shanghai to see my mother, now next to, it is not in any mood to continue, so please allow me to these "wonderful" the highlight left to the next

Source Share

The following is the source address of this work, no Silverlight development environment for the students, do not expect to open the project, but SilverlightApplication1 \ debug \ bin \ TestPage.htm still can run, I believe that you have installed Silverlight Runtime, of course not you will also be required to install Microsoft ~~ installed
here is a screenshot of the page to show once again that my art is very poor, so the interface is very simple, I want to point a button this thing we all use, so I do not to this interface explain the Download click here
image

After words

I once again thank you very much for trust companies to report, but hope it will not become a foreground and engineers ......

Remember that this version is a "toy", he must not be used for any more formal environment

Reproduced in: https: //www.cnblogs.com/GrayZhang/archive/2009/02/07/silverlight-popupbox.html

Guess you like

Origin blog.csdn.net/weixin_34326179/article/details/93272182