![](/img/trans.png)
[英]how to add dropshadoweffect to just the text of a textbox (programmatically)
[英]Apply DropShadowEffect to WPF Textbox text
如何將DropShadowEffect應用於TextBox的內容,而不是圍繞TextBox本身? 我希望文本具有與將DropShadowEffect應用於TextBlock相同的效果。
<TextBox>
<TextBox.Effect>
<DropShadowEffect ShadowDepth="4"
Direction="330"
Color="Black"
Opacity="0.5"
BlurRadius="4"/>
</TextBox.Effect>
</TextBox>
^這會在整個盒子周圍產生陰影。
<TextBlock>
<TextBlock.Effect>
<DropShadowEffect ShadowDepth="4"
Direction="330"
Color="Black"
Opacity="0.5"
BlurRadius="4"/>
</TextBlock.Effect>
</TextBlock>
^這是所需的外觀。 (但對於TextBox文本)
編輯:帶回家的消息是將着色器應用於控件的每個渲染像素。 如果只想將其應用到其中的一部分,請在該模板上的該級別上應用它,或者不渲染其他所有內容。
通過自定義TextBox
的ControlTemplate
,可以達到所需的效果:
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid x:Name="RootElement">
<!-- Use your effects on the ContentPresenter here. -->
<ContentPresenter Content="{TemplateBinding Padding}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
相反,您可能想從文本框中刪除“邊框”,“背景”和“焦點”矩形,以便仍然具有“文本框”功能:
<TextBox Background="Transparent"
BorderBrush="Transparent"
BorderThickness="0"
TextWrapping="Wrap">
<TextBox.Effect>
<DropShadowEffect ShadowDepth="4"
Direction="330"
Color="Black"
Opacity="0.5"
BlurRadius="4"
/>
</TextBox.Effect>
<TextBox.FocusVisualStyle>
<Style>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate/>
</Setter.Value>
</Setter>
</Style>
</TextBox.FocusVisualStyle>
</TextBox>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.