- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经为我的按钮定义了一种样式,其中包含使用阴影来增加深度。我在网上读到这有时会导致文本模糊,但可以在 WPF4 中使用以下方法解决:
TextOptions.TextFormattingMode="Display"
但是,我的按钮中的文本并不模糊,只是显示不正确,上面的代码没有改善显示效果。
带阴影:
没有阴影:
投影是在应用于按钮的样式中定义的。
<Style TargetType="Button" x:Key="RedButton">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="MinHeight" Value="25" />
<Setter Property="MinWidth" Value="70" />
<Setter Property="FontFamily" Value="Verdana" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border TextBlock.Foreground="{TemplateBinding Foreground}" x:Name="Border" CornerRadius="6" BorderThickness="1">
<Border.BorderBrush>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="{StaticResource DarkRedColor}" Offset="1.0" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.BorderBrush>
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="{StaticResource LightRedColor}" Offset="0.5" />
<GradientStop Color="{StaticResource DarkRedColor}" Offset="1" />
</LinearGradientBrush>
</Border.Background>
<Border.Effect>
<DropShadowEffect Color="Black" Opacity=".50" ShadowDepth="4" RenderingBias="Quality" />
</Border.Effect>.....
最佳答案
认为是因为 DropShadowEffect
试图应用于所有 child ,我想这就是 ContentPresenter
的地方在Style
试试这个:
<Style x:Key="RedButton"
TargetType="Button">
...
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Border x:Name="Border"
BorderThickness="1"
CornerRadius="6"
TextBlock.Foreground="{TemplateBinding Foreground}">
<Border.BorderBrush>
<LinearGradientBrush StartPoint="0,0"
EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Offset="1.0"
Color="{StaticResource DarkRedColor}" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.BorderBrush>
<Border.Background>
<LinearGradientBrush StartPoint="0.5,0"
EndPoint="0.5,1">
<GradientStop Offset="0.5"
Color="{StaticResource LightRedColor}" />
<GradientStop Offset="1"
Color="{StaticResource DarkRedColor}" />
</LinearGradientBrush>
</Border.Background>
<Border.Effect>
<DropShadowEffect Opacity=".50"
RenderingBias="Quality"
ShadowDepth="4"
Color="Black" />
</Border.Effect>
</Border>
<Border BorderThickness="1"
CornerRadius="6"
TextBlock.Foreground="{TemplateBinding Foreground}">
<ContentPresenter />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
关于WPF DropShadowEffect 中断按钮中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16056604/
是否可以有DropShadowEffect渲染阴影时忽略某些颜色?有某种蒙版(颜色选择性)阴影? 我的问题是什么阴影可以分配给整个视觉元素(图形)。它看起来像这样: 而且我要 注意没有阴影的网格线(除
禁用 DropShadowEffect 的最佳方法是什么,例如,如果您知道自己正在远程 session 中运行? 我可以考虑将颜色设置为透明,将模糊半径设置为 0,或将不透明度设置为零,但不确定这些选
我观察到将 DropShadowEffect 应用于 UIElement 偶尔会导致 UIElement 的内容有点模糊。这是一个非常讨厌的效果:它可能导致照片失去焦点或更糟 - 使整个“弹出”区域完
我有一个带有 DropShadowEffect 的 TextBlock。某些阴影颜色显示的颜色比指定的颜色更暗,就好像它们是有色的一样。但是,并非每种颜色都会发生这种情况。有谁知道原因或纠正方法? 这
我已经为我的按钮定义了一种样式,其中包含使用阴影来增加深度。我在网上读到这有时会导致文本模糊,但可以在 WPF4 中使用以下方法解决: TextOptions.TextFormattingMode="
我有一个 WPF 项目,其边框使用以下样式。计划是让发光效果在鼠标移过边框时淡入,在离开边框时淡出。
我有一个 Border,它由其他 UI 控件组成,例如 Canvas、Buttons、ComboBox 等。我只想在 Border 上有一个 DropShadowEffect,但所有子控件最终都会继承
我正在编写一个 WPF 自定义控件,它显示加载过程的叠加层。此自定义控件源自 ContentControl并重复使用它的 Effect显示投影的依赖属性。 然而,投影意外且意外地显示了两次。我试图找到
我有一个文本框,它在某个时候以编程方式添加到 Canvas ,我希望所有文本都具有投影效果,但我不希望该效果应用于文本框本身的边框。我该怎么做呢?向文本框添加 dropshadoweffect 将效果
我想覆盖 ContextMenu 的样式。 这是我的风格: #808080
我正在编写一个应用程序,它本质上是一堆松散的 xaml 屏幕 - 没有代码隐藏,只是在运行时动态链接到 ViewModel。 周末在一台旧电脑上运行这个程序时,发生了崩溃。跟踪和重新创建显示 igdu
我注意到 Windows Phone 7 的 Silverlight 中缺少效果属性,因此我进行了一些谷歌搜索,显然由于性能原因它被删除了。我基本上想做这样的事情
我是一名优秀的程序员,十分优秀!