模糊WPF容器的背景
最终,我想要实现的是在某种程度上复制 WPF 内容控件的 Aero glass 功能。
如果我将 BlurEffect
应用于包含 TextBlock
的 StackPanel
,我会将 TextBlock
的文本模糊化。
考虑一个例子:
无模糊
和
但是有没有一种 WPF 方法可以模糊面板后面的背景,而不是它的内容?
StackPanel
的背景是桌面,并且托管它的窗口设置为 AllowTransparency="True"
以允许自定义形状的外观。
Ultimately, what I want to achieve is a replication to some extend, of an Aero glass functionality of a WPF content control.
If I apply the BlurEffect
to a StackPanel
that contains a TextBlock
, I will have the TextBlock
's text blurred.
Consider an examples:
No blur
and with <BlurEffect Radius="5" KernelType="Gaussian"/>
But is there a WPF way to blur the background behind the panel, and not it's contents?
The background of the StackPanel
is a desktop, and the window that hosts it is set to AllowTransparency="True"
to allow the custom-shaped look.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不,这是不可能的。该效果应用于元素及其所有子元素,但您可以轻松地将 TextBlock 放置在容器外部,而不是容器内部。
通常你会使用像这样的网格:
在你的例子中,这没有什么区别。你到底想模糊什么?
no, it is not possible. The Effect is applied to the element and all its children but you can easily place the TextBlock outside the container, rather than inside it.
Normally you would use a grid like so:
In your example that will make no difference though. What, exactly, are you trying to blur?
StackPanel的背景是什么?图像画笔?如果是这样,为什么不能应用 BlurEffect 呢?
如果这不可能,那么尝试这个..
1] 使用图像并将其完全绘制在
Grid
上,因为我发现您不需要TileEffect
。将BlurEffect
添加到此Image
。确保均匀地填充图像。2] 然后添加具有透明背景的
StackPanel
作为Grid
中的下一个子,即不要颠倒图像和stackpanel的顺序。3]然后在StackPanel中添加
TextBlock
。或者
如果您坚持使用
Brush
设置为面板的背景,则使用VisualBrush
绘制模糊图像作为堆栈面板的背景,而不是ImageBrush
。如果这些提示有帮助,请告诉我。
What the background of the StackPanel? an ImageBrush? If so why cant you apply BlurEffect to that?
If that is not possible then try this..
1] Use an image and draw it completely over
Grid
as I see you dont want aTileEffect
. AddBlurEffect
to thisImage
. Make sure you fill image the uniformly.2] Then add
StackPanel
with transparent background as next child in theGrid
i.e. dont reverse the order of image and stackpanel.3] Then add
TextBlock
in StackPanel.OR
If you insist on using a
Brush
to be set as the backgrounnd of the panel then useVisualBrush
that draws a blurred image as background of the stackpanel, instead ofImageBrush
.Let me know if any of these tips help.
您可以在 Systems.Window 上使用 SetWindowCompositionAttribute,但随后您必须将 WindowStyle 设置为“None”并实现您自己的本机 Window 功能和句柄。从自定义控件继承也是相当复杂的。长话短说,有 BlurryControls。
您可以通过 NuGet 浏览“BlurryControls”找到它,或者在
在 GitHub 上,您还可以找到一个名为 BlurryWindowInvoker 的示例应用程序。
You can use the SetWindowCompositionAttribute on a Systems.Window, but you are then forced to set the WindowStyle to "None" and implement your own native Window funtionality and handles. Also inheriting from a custom control is quite complicated. Long story short, there's BlurryControls.
You can find it via NuGet by browsing for "BlurryControls" or check out the code yourself on GitHub. Eitherway, I hope this is helpful. It uses .NET 4.5.2 and only works for Windows10, since there is no solution to this problem on Windows8, and in earlier versions (Windows7 and Vista) you can achieve this by accessing DwmEnableBlurBehindWindow.
On GitHub you will also find a sample application called BlurryWindowInvoker.
您可以将其应用于网格。
You could apply this to a Grid.
我的五分钱,已经晚了:
您使用控件本身作为模板并从父容器复制图像,现在您可以模糊它并在顶部显示内容:
My Five cents, years to late:
You use the control itself as stencil and copy the image from the parent container, now you can blurr it and show things on top: