Transparent floating window. - wpf

I'm trying to create transparent floating dockable window. But, having difficulting achieving this. Tried Opacity, but no luck.
Here is a snapshot of my code :
// Floating dockable split pane
SplitPane splitFloating = new SplitPane();
XamDockManager.SetInitialLocation(splitFloating, InitialPaneLocation.DockableFloating);
XamDockManager.SetFloatingLocation(splitFloating, new Point(my.XCoordinate, my.YCoordinate));
XamDockManager.SetFloatingSize(splitFloating, new Size(my.Width, my.Height));
TabGroupPane tgpFloating = new TabGroupPane();
ContentPane cpRichText = new ContentPane();
cpRichText.Content = new RichTextBox();
cpRichText.Opacity = 0.0;
tgpFloating.Items.Add(cpRichText);
tgpFloating.Opacity = 0.0;
splitFloating.Panes.Add(tgpFloating);
splitFloating.Opacity = 0.0;
this.DockManager.Panes.Add(splitFloating);
this.DockManager.Opacity = 0.0;

I don't know much about the Infragistics suite, but generally speaking you should set you Background to Transparent (if you want to be able to click on the background) or {x:Null} (if you want to click through the background).
Also if it's a window (derives from System.Windows.Controls.Window), you'll need to set AllowsTransparency to true as well, but this might incur some loss of performance.

Related

Remove black flicker on first show of Winform with TransparencyKey set

The following code produces a black flicker on the screen right before the form is displayed (transparently), I'm wondering what my options are for removing that flicker?
Form f = new Form();
f.BackColor = Color.Lime;
f.TransparencyKey = f.BackColor;
f.StartPosition = FormStartPosition.Manual;
f.Bounds = Screen.PrimaryScreen.WorkingArea;
f.Show();
I get the same results if I create a new project, set the background of the form to Lime and the TransparencyKey to Lime, then click Run.
Things I've tried:
Set Opacity to 99% -- same flicker
Force WS_EX_COMPOSITED in OnCreateParams or using SetWindowLong -- same flicker
Show the window smaller, or 0 width, or off screen, then move to desired location -- causes bad display issues where the windows behind my form do not redraw correctly.
Setting ControlStyles.Opaque, ControlStyles.UserPaint, and several other ControlStyles combos and overriding different paint/background-paint events -- various results, either same flicker, worse flicker, or form not transparent.
Moving to WPF might be an option, but not really looking for "use WPF" as an answer.
Set the Opacity to 0.01.
If you need the form (or parts of it) visible - then re-set the Opacity once the form creation is complete:
Form f = new Form { Opacity = 0.01 };
f.Show();
f.BeginInvoke( new Action(() => f.Opacity = 0.99 ));
EDIT: Updated cleaner as Tergiver suggested

How to accelerate WPF fade in/out animation

I implemented lightbox effect with window's opacity change whilst fading in/out. When I have my window maximized this effect has big delay or when I use duration property then opacity change is not smooth.
I manage this eg. with like here:
DoubleAnimation animate = new DoubleAnimation();
animate.From = 1.0;
animate.To = 0.5;
animate.Duration = new Duration(TimeSpan.FromSeconds(0));
this.BeginAnimation(Window.OpacityProperty, animate); // main window
Window1 win = new Window1(); // new window to get focus
win.ShowDialog();
Tell me please, if you know, does this effect works on GPU by default? If not, can I manage this somehow?
The maximization issue sounds like the computer might have performance issues, and the Duration issue exists because you set it to 0, a zero second animation is instant, of course it is not smooth.

Can't consistently maximize WPF window

I have a minimized WPF window. I click the item in the taskbar to maximize. It makes a little audio ding, then I try again, and again. Usually about the third try it will maximize. What could cause it to refuse my initial maximize attempt?
One possibility is that you have some code that's changing the value of the ResizeMode property to NoResize.
See this page for more: http://msdn.microsoft.com/en-us/library/ms748948.aspx
Second, you might be overriding OnStateChanged and not calling base.OnStateChanged() consistently.
Third, you may have something hogging the UI's thread during your first attempts. Once that task--whatever it is--stops blocking then WPF can repaint the window in restored/maximized state.
I had a similar problem when trying to manually maximize a custom window.
The solution was to put the next code in my maximize button...
this.SizeToContent = System.Windows.SizeToContent.Manual;
this.MaxWidth = double.PositiveInfinity;
this.MaxHeight = double.PositiveInfinity;
this.Width = double.NaN;
this.Height = double.NaN;
this.WindowState = WindowState.Maximized;
Where 'this' referes to the Window.

How can I hide the cursor in transparent WPF window?

How can I hide the cursor in a WPF window that is fully transparent (alpha=0).
I tried the usual
this.Cursor = System.Windows.Input.Cursors.None;
and it works on areas with content where alpha > 0 but when the cursor moves to an area - in the same window - where the background is fully transparent the cursor re-appears.
I also added
System.Windows.Input.Mouse.OverrideCursor = System.Windows.Input.Cursors.None;
but that didn't help.
I realize that setting the alpha of background to 1 might be a solution but for various reasons this creates other problems...
Maybe as a work-around you can create a tiny non-transparent area somewhere, and move the mouse there just before hiding it:
// Coordinates of your non-transparent area:
var x = 10;
var y = 10;
System.Windows.Forms.Cursor.Position = new System.Drawing.Point(x, y);
this.Cursor = System.Windows.Input.Cursors.None;

Image Flipping in WPF

How do you get an image to be reflected in wpf without using the xaml? I have a rectangle with a BitmapImageBrush as its fill. I want to be able to regularly flip this image (X-axis) back and forth at will in C#. I've read about using the ScaleTransform property but this only seems to work in the xaml and that's not what I want.
This is how the image is created:
ImageBrush l = new ImageBrush(new BitmapImage(new Uri(uriPath, UriKind.Relative)));
_animation.Add(l);
_visual = new Rectangle();
_visual.Fill = _animation[0];
_visual.Width = width;
_visual.Height = height;
_visual.Visibility = Visibility.Visible;
_window.GameCanvas.Children.Add(_visual);
_animation is a list of ImageBrushes.
This is really simple, yet I can't seem to figure out how to do it. Please help.
You can still add a scale transform programmatically, rather than using xaml.
For instance, in this article.
To do the flip, set your scale transform to be negative in the direction you want to flip (ie, if horizontal, set x to -1, or -desiredScale if you also want to resize).

Resources