wpf 透明 UIElement.Opacity Property

UIElement.Opacity Property

Gets or sets the opacity factor applied to the entire UIElement when it is rendered in the user interface (UI). This is a dependency property.

C#
[System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)]
public double Opacity { get; set; }

Property Value

Double

The opacity factor. Default opacity is 1.0. Expected values are between 0.0 and 1.0.

Attributes

Remarks

The 1.0 default value is the default provided by the initial metadata of this dependency property on the UIElement class. Other derived classes may potentially change this default value by overriding the metadata from within their class constructor.

The value of Opacity won't be applied to actual layout unless the element is also visible (IsVisible is true).

Opacity is applied from parent elements on down the element tree to child elements, but the visible effects of the nested opacity settings aren't indicated in the property value of individual child elements. For instance, if a list has a 50% (0.5) opacity and one of its list items has its own opacity set to 20% (0.2), the net visible opacity for that list item will be rendered as if it were 10% (0.1), but the property value of the list item Opacity property would still be 0.2 when queried.

Even if the declared or evaluated opacity is 0, an element still participates in input events and commands, and is potentially focusable. This aspect can be useful, for instance you can use an opacity-zero object (such as a shape) for masking underlying objects with transparent elements. The opacity-zero object can then handle all the input event processing for an underlying area. However, the Background or Fill of the object or shape should be set to a value, even if it is Transparent, otherwise hit testing is not enabled, and no events are received.

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(112)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2020-06-20 哈佛大学公开课 幸福课 积极心理学
2019-06-20 Ajax
2019-06-20 jQuery FileUpload doesn't trigger 'done'
2019-06-20 Sending forms through JavaScript[form提交 form data]
2019-06-20 Sending form data
2019-06-20 Your first HTML form
2019-06-20 form submission
点击右上角即可分享
微信分享提示