积极答复者

问题
-
答案
-
你这样的叠加不就是将两个类似或者相同的控件,并且都有阴影效果上下放在一起。那不就是放两份Label就可以了, 你可以自己改变Label的模板如下:
<Style TargetType="Label"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Label"> <Border Background="{TemplateBinding Control.Background}" BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="{TemplateBinding Control.BorderThickness}" Padding="{TemplateBinding Control.Padding}" SnapsToDevicePixels="True"> <Grid> <ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" > <ContentPresenter.Effect> <DropShadowEffect Direction="0" ShadowDepth="0" Color="White" BlurRadius="15"/> </ContentPresenter.Effect> </ContentPresenter> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="UIElement.IsEnabled" Value="False"> <Setter Property="Control.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="Effect"> <Setter.Value> <DropShadowEffect Direction="0" ShadowDepth="0" Color="White" BlurRadius="15"/> </Setter.Value> </Setter> </Style>
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
- 已建议为答案 Jie BaoModerator 2012年6月4日 3:05
- 已标记为答案 Jie BaoModerator 2012年6月4日 3:23
全部回复
-
这种效果可以么?
我放在blend里做得 其实就是个 DropShadowEffect
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="WpfApplication2.MainWindow" Title="MainWindow" Height="350" Width="525"> <Grid x:Name="LayoutRoot" Background="black"> <Label Content="中华人民共和国" Margin="149,67,169.543,0" FontSize="25" VerticalAlignment="Top" Height="45.837" Foreground="White"> <Label.Effect> <DropShadowEffect Direction="0" ShadowDepth="0" Color="White" BlurRadius="15"/> </Label.Effect> </Label> </Grid> </Window>
至于要所有的Label嘛,那就用VisualTree去遍历一下呗
- 已建议为答案 Jie BaoModerator 2012年5月29日 2:46
- 取消建议作为答案 odfitbjhorfjhijmrothnsrtjntynytmtgmozsrtgjohsnurth 2012年5月29日 3:51
- 已建议为答案 Jie BaoModerator 2012年6月4日 3:05
- 已标记为答案 Jie BaoModerator 2012年6月4日 3:23
- 取消答案标记 odfitbjhorfjhijmrothnsrtjntynytmtgmozsrtgjohsnurth 2012年6月5日 3:36
- 取消建议作为答案 odfitbjhorfjhijmrothnsrtjntynytmtgmozsrtgjohsnurth 2013年1月31日 3:39
-
给一个没有Key的Style 只有TargetType="Label" 放入一个顶层资源Resources中, 就可以将这个样式应用到所有的Label了:
<Style TargetType="Label"> <Setter Property="Effect"> <Setter.Value> <DropShadowEffect Direction="0" ShadowDepth="0" Color="White" BlurRadius="15"/> </Setter.Value> </Setter> </Style>
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
-
WPF 4 中已经取消了OuterGlowBitmapEffect效果,微软建议效果可以自己通过Pixel Shader去实现, 或者这里一个开源库里面有很多效果http://wpffx.codeplex.com/
当然你可以看看这里的一个方案 http://www.bbniu.com/thread-956-1-1.html 用Blend SDK中的一个BloomEffect 来加强亮度,然后做一个相同的Label加上BlurEffect 作为背景,就可以达到较好的发光效果。
-----------------
我不是很明白你的叠加是什么意思,如果说Style继承的话 BasedOn就可以 http://msdn.microsoft.com/en-us/library/system.windows.style.basedon.aspx
如果说你要在这个Label中加上多个 Effect, 答案是不可以的,一个Element的Effect只能应用一个Effect。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
-
我不是很明白什么事你的阴影叠加,WPF中没有这种概念。 我给你的方案就是将一个没有Key的样式放到一个较高层的Resources中,这样这一层下的包括其元素内部的Label都会应用到这个样式。
你的阴影叠加的代码是怎么样的,让我看看,先让我明白你是怎么做的,我在继续你的思路给你说。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
-
你这样的叠加不就是将两个类似或者相同的控件,并且都有阴影效果上下放在一起。那不就是放两份Label就可以了, 你可以自己改变Label的模板如下:
<Style TargetType="Label"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Label"> <Border Background="{TemplateBinding Control.Background}" BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="{TemplateBinding Control.BorderThickness}" Padding="{TemplateBinding Control.Padding}" SnapsToDevicePixels="True"> <Grid> <ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" > <ContentPresenter.Effect> <DropShadowEffect Direction="0" ShadowDepth="0" Color="White" BlurRadius="15"/> </ContentPresenter.Effect> </ContentPresenter> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="UIElement.IsEnabled" Value="False"> <Setter Property="Control.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="Effect"> <Setter.Value> <DropShadowEffect Direction="0" ShadowDepth="0" Color="White" BlurRadius="15"/> </Setter.Value> </Setter> </Style>
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
- 已建议为答案 Jie BaoModerator 2012年6月4日 3:05
- 已标记为答案 Jie BaoModerator 2012年6月4日 3:23
-
可以 ,你只需要写着一个Style 就够了,不需要复制很多的。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
-
那就针对样式里面的Grid再加一层:
<Style TargetType="Label"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Label"> <Border Background="{TemplateBinding Control.Background}" BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="{TemplateBinding Control.BorderThickness}" Padding="{TemplateBinding Control.Padding}" SnapsToDevicePixels="True"> <Grid> <ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" > <ContentPresenter.Effect> <DropShadowEffect Direction="0" ShadowDepth="0" Color="White" BlurRadius="15"/> </ContentPresenter.Effect> </ContentPresenter> <Grid.Effect> <DropShadowEffect Direction="0" ShadowDepth="0" Color="White" BlurRadius="15"/> </Grid.Effect> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="UIElement.IsEnabled" Value="False"> <Setter Property="Control.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="Effect"> <Setter.Value> <DropShadowEffect Direction="0" ShadowDepth="0" Color="White" BlurRadius="15"/> </Setter.Value> </Setter> </Style>
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
-
所以,你要考虑是否要这么多发光和模糊。牺牲了性能而得到一些效果。
WPF通过DX渲染绘制,在刷新界面内容时候,他不是整体重绘,这点和GDI不一样,它是局部失效然后重绘,但是你的TextBox的输入会导致上方的Label的部分 也失效,所以一直在不断的进行绘制;而由于像素对齐等原因,在绘制时会产生模糊。导致感觉不佳。
当然,你也可以强制设置所有Label的Margin,让其它文字始终保持一定距离。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
-
人家有自己实现的本地库和一些第三方的特效库,其实我在我的第二个回复里面已经提到了,我们可以自己设计Pixel Shader(DX的HLSL语言), 通过DX的技术来渲染我们的界面元素。在DX的游戏也好,具有较高性能的特效也好,像素着色 (Pixel Shader)就提供了较好的解决方案。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us