HOWEVER, do not get discouraged (at least about this). In fact, it is fairly easy once you change your perspective a bit.
Overview:
To get this done you're essentially going to :
- create a full-screen "grey" box (label or HTML control)
- set it to be semi-transparent
- create an your dialog box (container, label, Text Input, image, HTML Control)
- "bring that to front" on your dialog box image
- drop your controls on top of that
- group all of the above
- set the visible property to be a local variable that you'll populate if/when you need to display the dialog box (e.g. l_Popup).
Grey everything out
Label Method
Drop in a Label control and delete the default "Text". Change the Fill value to something like:
- RGBA(0,0,0,.5); //half transparent black
The simple thing here is that it quickly lets you get it done w/ minimal fuss.
Image Method
If you're more of a graphic artist, then you might prefer this approach.
Create a new image (it doesn't have to be the size of your app) that is simply all grey in your (not-so-)favorite paint program (e.g. MS Paint will work). You can really just size your image, pick a grey, paint the whole thing and then save it. Nothing fancy. You can of course, get fancy and do pretty much any image.
In PowerApps,
- add a new image (click Insert | Media | Image)
- import the image you created above. (click View | Media | Browse | Open )
- drag it out to to cover the full size of your application screen.
With your image still selected, in the right-hand details area find the Transparency setting (or just type "tra" in the search field) and put in something that suits you (e.g. 40%).
This will give you the effect you're essentially after. You can still see everything on the page, but this new image will be "on top" of them and you cannot click on any control.
If you run your app now, you won't be able to click on any control you created earlier (which is how you'd expect a modal dialog to work).
Your Are a Web Developer and Want To Get Creative
Using the HTML method, you can get "fancy" and add a blur effect or lots of other things that may or may not work on all platforms. Please don't do anything too crazy and break the value of a platform that means you don't have to troubleshoot why things work on Android but not an iFauxn. Drop an HTML control into your app and size it to the full height/width of your screen. Add the following to the HtmlText property of that control:
"<div style='width:" & Self.Width & "px;height: " & Self.Height-1& "px;margin-top:0px;background:rgba(0,0,0,0.4);backdrop-filter:blur(5px);'></div>"
This will blur items behind the control. Probably. I don't know as I don't follow all the stupid HTML features that designers seem to be adamant about trying to implement which just break things.
I sure hope this works on all browsers/devices |
Add your dialog box
Container Method:
- Add a simple container (not vertical/horizontal).
- Increase the Drop Shadow if you'd like (Semi-Bold)
- Change the Fill to whatever color you'd like (Color.Orange)
- Change the Radius value(s) to optionally round the corners (50)
- Drop whatever other controls you want to be in the Popup (HTMLText, Button)
I used to include an approach to do a more creative popup w/ drop-shadows via PowerPoint. I've dumped it as the above is now solved. You can easily round the corners and add shadows w/ containers, so no need for that hack workaround.
However, you can still easily add in a Label (but you can't round the corners) and a similar fill property, or a Text Input (that you can round corners on / but then have to change the DisplayMode to View vs. Edit). Same principles apply to the above, but Containers are now likely the simplest method so you should just adopt that going forward.
Add text and controls
Once you have this, then just do as you normally would and drag your dialog text, icons, buttons, etc. onto the Dialog Box image above so that everything is laid out as you'd like it.There are some default icons from PowerApps that work well here and are already set up for handling clicks and events. In the example image below I added 3 text fields, altered their font size, made them bold and added two icons.
I know you're going to click Yes any minute now |
Again, this is because the new items we just created are in higher layers than your previously-created controls.
Group everything
You can even be a stickler (as I am) and name the entire group something meaningful.
Make it disappear
Make it reappear
- UpdateContext({l_Popup:true})
Note: If you're just getting started w/ variables in PowerApps, then note that this is a "local variable" that is only referenced on this page. Global variables are set completely differently. However, locals keep their value if/when you navigate on/off page sooo...sorta global?
In my case, I created a button on my form:
Click here for obligatory earworm |
Final Steps
- UpdateContext({l_Popup:false});Navigate(Screen2,ScreenTransition.Fade)
If that bothers you (it should), you should edit their Tab property on all controls to be something similar to:
- If(l_Popup,-1,1)
- If(!l_Popup,-1,1)
I also tend to try and ensure I'm setting control variables like this up and initializing them properly. That means changing the Screen's OnVisible event to include a similar bit of code:
- UpdateContext({l_Popup:false})
Interesting article. I found that this works better for some reason when the "dialog" items are set out in a group, and the overlay image is ordered just beneath under the grouped controls. I may experiment with providing more than one dialog on a screen later on.
ReplyDeleteThanks again.
Excellent article - many thanks.
ReplyDelete