prevent wpf window render black background without allowstransparency=true - wpf

I have some animations on a window that should be overall transparent and stretched over multiple screens.
I dont need the title bar or the background.
I would like to save resources.
When I set allowstransparency(bad for performance) to false the transparent background is rendered black.
Is there some lighter alternative to even prevent the window to render the background?
I did not find any thing on alternative rendering or windows. I see the window class inherits from Window : ContentControl, IWindowService but I guess I shouldnt look into that.
I dont have code to show accept at least that im using
<WindowChrome.WindowChrome>
<WindowChrome
CaptionHeight="0"
ResizeBorderThickness="0"
/>
</WindowChrome.WindowChrome>
To disable transparency paddings on a loose window without allowstransparency=true.

One of the things WindowChrome gives you is the ability to add certain Windows window's abilities to a custom design window you make.
Not necessarily related to transparent background.
If you want your window to have round edges you will need to set AllowTranspareny to True, otherwise you will get the black background, no way around that.

Related

XAML: How to set controls properties depending on screen resolution?

I'm developing WPF application (.NET 4) where I have few UserControl's which looks pretty good on most of the screens.
But now customer have new monitors where some elements are too small. The best solution we found is to make some elements smaller, to left more space for the main panel.
The layout is now pretty complex, and I spend a lot of time to find which margins, heights, widths and so on.. I need to change to implement this.
Usually it is some children elements Height, Width +-10 or so. Sometimes Margin. And in one case it's Style's Setter Property="Width" which defined in Resources.
I'm wondering is it possible to make this changes configurable, so for my specified screen resolution (let's say I know only that Width=X and Height=Y) they was applied, and for all other screens it stays the same as now?
How to do this using as less code-behind as possible?
I like the solution with VisualStateManager and VisualState.SateTriggers, but looks like my application does not recognize this.
When you are using user controls inside the window may be you could set the height and width of the grid's row and column definition to '*' and also make scroll bar visibility of horizontal and vertical scroll bar to auto.
Hope it helps you.

ImageViewer in WPF

Hi everyone I would like to implement an ImageViewer (like the one in Facebook for example) in a WPF application
I already have a ListBox whith my pictures, it works well. But I would like to add pop "image full size" when the user double click on one of them. (something like in FB, with a fade out of the background etc).
Currently I'm thinking of to use a Window...Do you have a better idea of what I should use ?
i would probably use a window for that as well. Then you can easily put an opacity animation when the window loads to give it the fade in and fade out effect
You could also use a Popup control.
It comes with some some built in (but very limited) animations, like fade, see PopupAnimation.
I'd try that and if it doesn't fit your needs, I second bflosabre91 oppionion and would use a separate opacity animated window.
But bear in mind that with an additional window you could have negative side effects e.g always sync the window positions correctly, handle task switches (ie. correctly hide the window in the taskbar/tasklist)

FlowDocument loses ClearType in child elements when placed in window with custom glass

So the new WPF 4 text rendering looks great, but enabling the aero glass effect on a window requires that you change the background to transparent, which of course disables ClearType rendering.
Using the provided RenderOptions.ClearTypeHint=Enabled allows you to designate child elements to reenable ClearType rendering from that point in the tree. I've found a few other topics that talk about doing this for the ScrollViewer used internally inside RichTextBox and FlowDocumentScrollViewer, and creating a custom style does indeed fix it so that my FlowDocument gets ClearType rendering again.
However, this only applies to top level paragraphs in the FlowDocument. If I add floaters or figures, or a table, any text inside them is inexplicably grayscale again. I know that the glass effect is to blame, since disabling it reenables the ClearType rendering.
I looked through the visual tree with Snoop, but both the main content (which renders properly) and the sub-content (which is grayscale) have similar element hierarchies without anything to which I can attach RenderOptions.ClearTypeHint.
Has anyone run into this problem? Is there a workaround or a solution? I checked Connect but there isn't any bug filed about this. It's quite an annoying problem.
After doing a lot more research, and comparing the way different controls work on and off of aero glass, I've found a few answers. The TextBox control doesn't work properly either, but portions of FlowDocument and things like TextBlock do, which prompted me to explore why.
After digging around in reflector for a while, I found that when using the advanced text formatting APIs to get text and render it onto a drawing context, the RenderOption flags essentially go ignored, since the drawing system knows from the root visual (the window) that transparency was enabled. Once that happens, all the RenderOptions flags in the world aren't going to get ClearType back.
I did happen to stumble on a work-around though. If you have access to the DrawingContext and are doing the low-level text rendering yourself, you can do a DrawRectangle behind the text with a fill, and ClearType gets reenabled. I assume that this is the only way for the renderer to be sure that it has a proper background to draw on.
So in summary, you need to do your own text drawing, and additionally you need to explicitly draw a background using the same DrawingContext behind your text in order for ClearType to get rendered properly.
I know this could get tedious, but have you tried setting general styles like so:
<Style TargetType="Paragraph">
<Setter Property="RenderOptions.ClearTypeHint" Value="Enabled"/>
</Style>

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.

Create a fully transparent WPF window to capture mouse events

I'm trying to trap mouse events in WPF by using a topmost, transparent non-modal window. I'm finding that this works fine if the opacity of the window is 0.01 or greater and it has a background color, but when the opacity is set to 0 it no longer receives mouse messages. Is there a way make this window look fully transparent and still get mouse input?
As far as I know, no.
When a Control or Window is fully transparent, it can then be clicked through. This is the case if you set your Window.Background="Transparent", or Opacity="0". As far as I know, this is by design in WPF.
When using an opacity of 0.01, you should barely see the window, if at all. This is likely your best bet at achieving the functionality.
Edit: Another solution, which I tried and does work, is to set the background color to an almost-transparent color. I used Background="#01000000", thus giving an alpha value of 1. This makes your window background transparent-looking, but allows you to place controls on it with the window at full opacity.
In Visual Studio 2010:
Select your window in your design view.
Set the properties of your window to:
AllowsTransparency : check it
Background : Transparent
WindowStyle : None
Just set Background=Brushes.Transparent instead of Background=null.
You don't need to use opacity at all (ie. just leave it at 100% opacity).
For example i think your control name is MyGrid and you want it be Transparent and always get MouseOverEvent.....
If (window AllowsTransparency is True and the window Background is Transparent) Then
use a color like #01777777 for MyGrid Background Or 0.01 for MyGrid Opacity.
Else
use something like #00777777 for MyGrid Background Or 0.00 for MyGrid Opacity.
Setting the opacity to 100% (or any non-zero value), and the background to Transparent (instead of null) should make most controls hittable.
Make sure to set IsHitTestVisible to true. Not all controls can be hit, even if the opacity is 100% and the background is transparent.
You might find it simpler to use Mouse.Capture.
https://msdn.microsoft.com/en-us/library/ms771301.aspx
When an object captures the mouse, all mouse related events are treated as if the object with mouse capture perform the event, even if the mouse pointer is over another object.

Resources