WPF改变亮度
嗯,我有一个黑白应用程序,我需要一个降低亮度的功能,我该怎么做? 所有白色都来自保存在 ResourceDictionary(Application.xaml) 中的 SolidColorBrush,我当前的解决方案是放置一个空窗口,其不透明度为 80%,但这不允许我使用底层窗口。
Well i have a application that is black and white and i need a function to lower the brightness how can i do this? all the white comes from a SolidColorBrush that is saved in a ResourceDictionary(Application.xaml), my current solution is to put a empty window that is back with 80% opacity over it but this does not allow me to use the underlying window..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的所有 UI 元素都使用相同的
Brush
,为什么不直接修改Brush
来降低亮度呢? 例如:在对被冻结的
Brush
发表评论后进行编辑:如果您使用的是内置画笔之一(通过
Brushes
class) 那么它将被冻结。 不要使用其中之一,而是声明您自己的Brush
而不冻结它:在 Robert 对应用程序级资源的评论后进行编辑:
Robert 是对的。 在
应用程序
级别添加的资源如果可冻结,则会自动冻结。 即使您明确要求不要冻结它们:我可以看到有两种解决方法:
Window
的Resources
集合中。 但这使得分享变得更加困难。作为 #2 的示例,请考虑以下内容。
App.xaml:
Window1.xaml:
Window1.xaml.cs:
它不是那么漂亮,但它是我能想到的最好的正确的现在。
If all your UI elements are using the same
Brush
, why not just modify theBrush
to reduce the brightness? For example:Edit after your comment on the
Brush
being frozen:If you're using one of the built-in brushes (via the
Brushes
class) then it will be frozen. Instead of using one of them, declare your ownBrush
without freezing it:Edit after Robert's comment on Application-level resources:
Robert is right. Resources added at the
Application
level are automatically frozen if they are freezable. Even if you explicitly ask for them not to be frozen:There are two ways around this that I can see:
Window
'sResources
collection. This makes it harder to share though.As an example of #2 consider the following.
App.xaml:
Window1.xaml:
Window1.xaml.cs:
It's not as pretty, but it's the best I can come up with right now.
通过更改我的根元素的不透明度来解决这个问题,而不是尝试修改画笔,但如果有人告诉我我是否可以做到这一点或它不可能,那仍然很好。
Solved this by changing the Opacity of my root element instead of trying to modify a brush but it would still be nice if some told me if i can do that some how or its not possible.
如果将
SolidColorBrush
添加到较低级别的资源中,Kent 的解决方案将起作用。 Freezables 添加到Application.Resources
后会自动冻结。Kent's solution will work if the
SolidColorBrush
is added to the resources at a lower level. Freezables are automatically frozen when they're added toApplication.Resources
.