Variable opacity within a WPF application - wpf

My problem is:
I have a Canvas which covers part of my Window. The Opacity of the canvas is set to less than 1, i.e. I can view the controls under the Canvas. What I would like to do is place a control, any control, say a Button, on the canvas and not have that Button semitransparent. Is this possible using WPF?

Try the alpha in the color of the canvas.

Related

Crop WPF control

I have to crop some control to show only a half of it but the rest should be transparent and clickable so it is not enough to cover the control with something. The result should give a control with only half of the content (for example 50% of top) and the rest should be cropped (not hidden) so some other control below should be visible and not overlapped by cropped part. New control should also scale when window is scaled. How to do this in WPF?
I have finally did the trick using Border around the control and Clip property of this border was set to Multibinging that was generating Rectangle basing on ActualWidth and ActualHeight of my control
Maybe GridSplitter:
http://www.wpf-tutorial.com/panels/gridsplitter/
Can be used to split views horizontally/vertically, and can be responsive.

WPF Canvas and DrawingVisuals disappear

I have a set of User Controls, derived from FrameworkElement. Each host one or more DrawingVisuals. These drawing visuals can represent text, graphics, progress meters etc and are used to display the states of various HMI devices.
These, appearance-wise work fine in a grid - images are rendered, text and backgrounds appear fine, dependency properties can be set. However, when I encapsulate them in a Canvas, they disappear all but for the drawing visuals representing labels. And even for these, only the text rendered by DrawingContext.DrawText is visible. Operations performed by dc.DrawImage, cd.DrawRectangle etc do not appear.
Can someone please shed some light on why this might be.
Thanks
Are you positioning your controls properly? In a grid you have margins for each item, where as in a canvas you have to set Canvas.Top and Canvas.Left for each element. Is it not that those items are hidden underneath something? Try using snoop to use if the controls are actually part of Canvas children or if they have not been added at all.
You can read more about Canvas on MSDN

Adding glass effect to listbox item

I have a stackpanel with a background image. Inside the stackpanel there is a ListBox and its background is set to transparent, what I need is to blur (glass effect) the background image only the part that comes under the listbox item. I tried to add a rectangle to transparent color in the listbox item template and then added a blurred effect but it doesn't work. This is what I am trying to achieve.
I came across this some time ago, maybe will help with what you're after.

WPF Adorner Clipping

I have an ItemsControl in a ScrollViewer. The items in the ItemsControl are expanded to a DataTemplate which basically consists of an Adorner.
Now the problem is, when scrolling, the Visual Children of the Adorner are visible outside the ScrollViewer. Lets say I scroll from the Horizontal Offset 0 to 100, the Visual Children of the Adorner move to the left and are visible next to the ScrollViewer, although they should be hidden. Setting ClipToBounds on the ItemsControl or the ScrollViewer does not work.
I understand, that Adorner are rendered above all elements z-order wise, but they really shouldn't be visible in such cases as with the ScrollViewer. The adorned Element by the way behaves like expected and is not visible through the ScrollViewer.
Is there any easy way to "clip" the Adorners, so that they are only visible in the visible scroll area?
Thanks,
Andrej
Setting ClipToBounds on the containing control is not enough. You must set the adorner's IsClipEnabled property too.
I've encountered the same problem when subclassing the WPFToolkit DataGrid to draw an adorner around the current cell.
The content of the ScrollViewer is rendered by a ScrollContentPresenter instance. ScrollContentPresenter has its own adorner layer, which is accessible through the ScrollContentPresenter.AdornerLayer property.
I found that my adorner correctly clips if I add it to that layer.
My solution was to push a clip region onto the drawing context, render whatever I needed, and pop the clipping at the end, like this:
drawingContext.PushClip(new RectangleGeometry(new Rect(0, 0, this.AdornedElement.RenderSize.Width, this.AdornedElement.RenderSize.Height)));
// continue drawing
drawingContext.Pop();
You can plug this in into any Adorner, the bounds are already available as part of the element.

Showing Tooltip of WPF control under the decrative touches

I have a window with a number of controls upon it, each control with a Tooltip associated. In an effort to jazz up the window a little, I have overlayed some semi-transparent ellipses which gives the whole window a glossy finish, however, in some cases the positioning of these ellipses are preventing the hit-test getting down to my controls.
How can I have the ellipses visible, but transparent from a hit-test point-of-view?
IsHitTestVisible = false

Resources