WPF 对按钮文本的影响
WPF Effects on Button Text
我尝试在 App.xaml 中的按钮文本中添加发光效果,但我找不到有关如何操作的任何信息。我找到的所有效果都应用于完成按钮。
这是我的代码:
<Application x:Class="RSPolar.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style TargetType="Button">
<Setter Property="FontSize" Value="48">
</Setter>
<Setter Property="Foreground" Value="#00EE00">
</Setter>
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="Gray" Offset="1"/>
<GradientStop Color="DarkGray" Offset="0.52"/>
<GradientStop Color="Gray" Offset="0.5"/>
<GradientStop Color="LightGray" Offset="0.48"/>
<GradientStop Color="WhiteSmoke" Offset="0"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Button.Effect">
<Setter.Value>
<DropShadowEffect Color="Black" Direction="320" ShadowDepth="3" BlurRadius="10" Opacity="0.5" />
</Setter.Value>
</Setter>
<Setter Property="Button.Effect">
<Setter.Value>
<BlurEffect Radius="1"></BlurEffect>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
</Application>
尝试在按钮中添加带有效果的文本块作为内容。
<Window.Resources>
<Style TargetType="Button">
<Setter Property="FontSize" Value="48">
</Setter>
<Setter Property="Foreground" Value="#00EE00">
</Setter>
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="Gray" Offset="1"/>
<GradientStop Color="DarkGray" Offset="0.52"/>
<GradientStop Color="Gray" Offset="0.5"/>
<GradientStop Color="LightGray" Offset="0.48"/>
<GradientStop Color="WhiteSmoke" Offset="0"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Button.Effect">
<Setter.Value>
<DropShadowEffect Color="Black" Direction="320" ShadowDepth="3" BlurRadius="10" Opacity="0.5" />
</Setter.Value>
</Setter>
<Setter Property="Button.Effect">
<Setter.Value>
<BlurEffect Radius="1"></BlurEffect>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Button Width="300" Height="200">
<TextBlock Text="Content">
<TextBlock.Effect>
<DropShadowEffect BlurRadius="8" Color="#00EE00" ShadowDepth="0"/>
</TextBlock.Effect>
</TextBlock>
</Button>
更新
在样式中使用 ContentTemplate,您可以将它用于所有按钮。
<Window.Resources>
<Style TargetType="Button">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock FontSize="48" Foreground="#00EE00" Text="{Binding Path=Content,RelativeSource={RelativeSource AncestorType={x:Type Button}}}">
<TextBlock.Effect>
<DropShadowEffect BlurRadius="8" Color="#00EE00" ShadowDepth="0"/>
</TextBlock.Effect>
</TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="Gray" Offset="1"/>
<GradientStop Color="DarkGray" Offset="0.52"/>
<GradientStop Color="Gray" Offset="0.5"/>
<GradientStop Color="LightGray" Offset="0.48"/>
<GradientStop Color="WhiteSmoke" Offset="0"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Button.Effect">
<Setter.Value>
<DropShadowEffect Color="Black" Direction="320" ShadowDepth="3" BlurRadius="10" Opacity="0.5" />
</Setter.Value>
</Setter>
<Setter Property="Button.Effect">
<Setter.Value>
<BlurEffect Radius="1"></BlurEffect>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<StackPanel>
<Button Width="300" Content="content1" Height="200"/>
<Button Width="300" Content="content2" Margin="0,10,0,0" Height="200"/>
</StackPanel>
我尝试在 App.xaml 中的按钮文本中添加发光效果,但我找不到有关如何操作的任何信息。我找到的所有效果都应用于完成按钮。
这是我的代码:
<Application x:Class="RSPolar.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style TargetType="Button">
<Setter Property="FontSize" Value="48">
</Setter>
<Setter Property="Foreground" Value="#00EE00">
</Setter>
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="Gray" Offset="1"/>
<GradientStop Color="DarkGray" Offset="0.52"/>
<GradientStop Color="Gray" Offset="0.5"/>
<GradientStop Color="LightGray" Offset="0.48"/>
<GradientStop Color="WhiteSmoke" Offset="0"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Button.Effect">
<Setter.Value>
<DropShadowEffect Color="Black" Direction="320" ShadowDepth="3" BlurRadius="10" Opacity="0.5" />
</Setter.Value>
</Setter>
<Setter Property="Button.Effect">
<Setter.Value>
<BlurEffect Radius="1"></BlurEffect>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
</Application>
尝试在按钮中添加带有效果的文本块作为内容。
<Window.Resources>
<Style TargetType="Button">
<Setter Property="FontSize" Value="48">
</Setter>
<Setter Property="Foreground" Value="#00EE00">
</Setter>
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="Gray" Offset="1"/>
<GradientStop Color="DarkGray" Offset="0.52"/>
<GradientStop Color="Gray" Offset="0.5"/>
<GradientStop Color="LightGray" Offset="0.48"/>
<GradientStop Color="WhiteSmoke" Offset="0"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Button.Effect">
<Setter.Value>
<DropShadowEffect Color="Black" Direction="320" ShadowDepth="3" BlurRadius="10" Opacity="0.5" />
</Setter.Value>
</Setter>
<Setter Property="Button.Effect">
<Setter.Value>
<BlurEffect Radius="1"></BlurEffect>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Button Width="300" Height="200">
<TextBlock Text="Content">
<TextBlock.Effect>
<DropShadowEffect BlurRadius="8" Color="#00EE00" ShadowDepth="0"/>
</TextBlock.Effect>
</TextBlock>
</Button>
更新
在样式中使用 ContentTemplate,您可以将它用于所有按钮。
<Window.Resources>
<Style TargetType="Button">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock FontSize="48" Foreground="#00EE00" Text="{Binding Path=Content,RelativeSource={RelativeSource AncestorType={x:Type Button}}}">
<TextBlock.Effect>
<DropShadowEffect BlurRadius="8" Color="#00EE00" ShadowDepth="0"/>
</TextBlock.Effect>
</TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="Gray" Offset="1"/>
<GradientStop Color="DarkGray" Offset="0.52"/>
<GradientStop Color="Gray" Offset="0.5"/>
<GradientStop Color="LightGray" Offset="0.48"/>
<GradientStop Color="WhiteSmoke" Offset="0"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Button.Effect">
<Setter.Value>
<DropShadowEffect Color="Black" Direction="320" ShadowDepth="3" BlurRadius="10" Opacity="0.5" />
</Setter.Value>
</Setter>
<Setter Property="Button.Effect">
<Setter.Value>
<BlurEffect Radius="1"></BlurEffect>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<StackPanel>
<Button Width="300" Content="content1" Height="200"/>
<Button Width="300" Content="content2" Margin="0,10,0,0" Height="200"/>
</StackPanel>