WPF opacity mask by cutting display child controls

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: HTTPS: //blog.csdn.net/Backspace110/article/details/86635290
WPF opacity mask by cutting child controls display
child controls beyond the parent controls shows that the region
using a mask to mask mask display child controls
opacity mask OpacityMask board
copy the code
sub-control parent control shows that the region beyond
the WPF development process, often encounter rounded controls, we generally achieved by Border, but if we put the child to control the control, while the control sub-set distance from the left side and top of 0, then the child would exceed the control parent control fillet display range.


Use mask mask to mask display child controls
outermost or Border, but we add a Grid inside, and then add a mask to the Grid's visual brush (OpacityMask),
add a Border in the brush, peripheral border width, height, rounded, and brush border thickness in turn is bound to the border.

Note 1 can not be added directly to the outermost Borde opacity mask, when the outer Border has a border, you can not handle perfectly rounded corners, as used herein Grid mask do
note 2, Grid need to set the background color, transparency can be, but the default value can not be {x: Null}
Note 3, the brush Border Height and Width Border required Binding of the peripheral and ActualHeight ActualWidth
note 4, when the party Templete for control, there will be run in the console wpf binding error Indication (wpf bug ??), you can now be visualized in the brush in the background Border OnApplyTemplate code rewriting () for Binding

 

OpacityMask opacity mask
mask does not distinguish a specific color, the upper mask is located in the control, a transparent or {x: null} Mengban completely solid, the lower the opacity of the mask, corresponding to the dark portion of the display control, or just masking effect, the transparency was changed to 0.1. clearly see the child controls are very dim.

----------------
Disclaimer: This article is CSDN blogger original article "e1ki0lp", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/backspace110/article/details/86635290

 

 

https://blog.csdn.net/backspace110/article/details/86635290

Guess you like

Origin www.cnblogs.com/fengjj/p/11599647.html