How can I overlay a control on a window? - wpf

Right now I have a normal window with a bunch of controls.
When the user hits a certain button I want to dim the entire window and then display a popup on top of it. Not a true dialog box, just something that is inside the window.
So this is my theory...
Every control is on layer 0.
There is a rectangle the same size as the form in layer 1. This has 50% transparency.
My popup is loaded into layer 2.
Clicking anywhere on the rectangle will do the same thing as pressing close on the pop-up.
Is this possible?

This is perfectly possible.
Put your entire UI in any panel inside of a <Grid>.
Then, in the same grid, put a <Rectangle Opacity=".5" Visibility="Collapsed" /> for the overlay and a centered panel for the popup.
Handle the rectangle's click event and hide the popup.

Related

WPF Control form resize

I have two controls on my form, i have two use case
When i drag from the right corner, i want to re size the form and all controls should be aligned appropriately
When i drag from the right edge, the right side controls should be hidden
I have already tried the Res size mode as can re size and i can handle the first user scenario.
I have used a View Box property which is enabling the re size of window when i drag and shrink it.
I am not able to find a control that can allow me to re size and hide a portion of the window at two different events
Some ideas for you.
You may handle the SizeChanged event for your window.
SizeChangedEventArgs has two propertis: HeightChanged, WidthChanged.
Maybe you can collapse the viewbox when only Widthchanged is ture.
Update:
After tested, Collapse viewbox will collapse the content in viewbox. So I write code like below to avoid this issue. But It's worked not very well. Just FYI:
<Grid>
<Viewbox>
<content/>
</Viewbox>
<content/>
</Grid>

WPF Hidden ScrollViewer's Bars

I need a ScrollViewer for WPF application which like on some web pages (like Facebook), scroll bars are hidden even if content is long, but when mouse is over bars become visible. Anyone have idea how to do that?
Tnx.
MVVM focused answer:
I'm sure there is a property which allows you to hide or show the scroll bars.
Bind this property to your ViewModel.
Create a MouseOver event which fires when the mouse moves into a certain part of the screen. To do this, you could overlay an invisible grid over the screen, with the right hand 10% as the target area.
Now when the mouse enters the region, show the scrollbar, and when it exits the region, hide the scrollbar.
Ensure that you set the MinWidth on the invisible region, so that if the window gets narrow, the scrollbar trigger area is still wide enough to be usable.

How to create a UserControl with an irregular shape?

In my Silverlight 4 application I need to create a user control with an irregular shape. The "main display" of the UC is a standard rectangle but I need to have tabs (simple text blocks, where the user can click) that are outside of the main display rectangle.
Is this possible with Silverlight 4? If so, how?
Thanks in advance.
You can position elements of a control outside its normal layout in a number of ways. You could use Canvas but if most of the control is standard Grid rectangle then you can use a Grid. The trick is to use negative Margins.
<Grid x:Name="LayoutRoot">
<Border Margin="0 -22 0 0">
<TextBlock Text="I appear above the UserControl layout" />
</Border>
</Grid>
Note that if the Usercontrol is being used as the Visual root then this won't work because the Silverlight plugin will not render beyound its client rectangle.
It is, you can have transparent background behind the tabs which can let clicks through, effectively behaving as if the shape was different. The UserControl will still have a rectangular shape including the tabs, unless you wrap then into a Popup and float out of the UC with some offset.
Technically, you can have elements outside the UserControl's rectangle if you use a Canvas for your LayoutRoot instead of a Grid. Elements in a Canvas aren't clipped to the canvas size. I wouldn't recommend this, however, because you won't be able to use Margin to size and align your controls inside it. It would be better to have all child controls inside a Grid LayoutRoot.
Which brings us to the question of irregularity. If you want to 'see through' parts of the control and be able to click through them (i.e. click objects underneath it), all you need to do is keep the UserControl's and the LayoutRoot's Background to null or just not set it at all. Wherever there is a lack of any background, clicks will go through. Note that if you set the background to Transparent it will make the control behave as a rectangle (as if it's filled with solid color) with respect to mouse input.
Another thing is if you want to see HTML controls under the see-through parts of your app. Then, you'll have to use windowless mode, but that's another can of worms.

Best way to animate arrow levitating over notification area in WPF

At some point in my app the main window closes and the application continues to run as a system tray icon.
Whenever this happens, I want to show the user, that the app is now in the notification area as an icon. I could just show a tooltip, but it's not cool anymore.
Instead, I want to levitate a big arrow over an icon, to be sure that the user sees it.
Here is how it's done in DropBox application:
http://img59.imageshack.us/img59/9364/arrowva.png
What is the best way to create and animate this arrow in WPF:
A custom shape window? If so, what will do the animation. Can I apply storyboard animation to a window itself?
A transparent larger window, but with arrow as an Image, and animate it with storyboard? But than, I will have the window capture mouse clicks, which is not desired.
Some other approach?
Thank you.
You can use Popup with explicit position:
<Popup AllowTransparency="True" IsOpen="True" Placement="AbsolutePoint"
HorizontalOffcet="{x:Static namespace:TrayInfo.LocationX}"
VerticalOffcet="{x:Static namespace:TrayInfo.LocationY}" >
<views:YourViewWithAnimatingArrowImage DataContext="{Binding ifYouNeed}" />
</Popup>
TrayInfo
since u can't really animate a window, (it's a user32 thing, not a wpf element), I'd go with option 2.

WPF window scrolling with top menu

I'm running into a dilemma. When I make the ScrollViewer the main content object of my window, scrolling behaves exactly like I want it to. You resize to make it smaller than the content and the window and scroll bars appear. The problem comes in when I want the to menu to be static and the rest of content to be scrollable. I want the scroll bars to behave the same way as a browser window does, meaning when you resize it, the scroll bars appear based on the size of the content. When you expand the window, the content takes up the entire real estate of the window. Is that possible in WPF?
Help would be GREATLY appreciated.
Make a DockPanel the main content object of your window. Insert your top menu as the first child (with DockPanel.Dock="Top") and the ScrollViewer (containing the rest of the window's content) as the second child. In a DockPanel, the last child takes up all the remaining space, which should be what you want.
<Window ...>
<DockPanel>
<MyMenu DockPanel.Dock="Top" ... />
<ScrollViewer>
....
</ScrollViewer>
</DockPanel>
</Window>

Resources