如何增加 mahapps.metro 文本框水印文本的字体大小
How to increase the font size of the mahapps.metro Textbox's watermark text
如何在下面的 WPF 代码中增加水印文本的字体大小('8 小时'):
<TextBox x:Name="txt8HoursArm1"
Margin="5"
Grid.Column="1"
IsTabStop="False"
Style="{StaticResource PrimaryInputTextBoxStyle}"
Controls:TextBoxHelper.UseFloatingWatermark="True"
Controls:TextBoxHelper.Watermark="8 Hours"
IsEnabled="False"
Text="1"
GotFocus="txt_GotFocus"
PreviewTextInput="txt_PreviewTextInput"
TextChanged="txt_TextChanged" FontSize="14" />
请看下图的文本框
或者您可以创建自己的风格,完全控制一切:
<Style x:Key="TaggedTextBox" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="Hotpink"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Height" Value="32"/>
<Setter Property="FontSize" Value="15" />
<Setter Property="FontFamily" Value="Arial" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid>
<TextBox HorizontalContentAlignment="Left" Text="{TemplateBinding Text}" Background="{TemplateBinding Background}" VerticalContentAlignment="Bottom" Foreground="{TemplateBinding Foreground}" FontSize="{TemplateBinding FontSize}" />
<TextBlock Foreground="Lime" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="10" Margin="5,2" Text="{TemplateBinding Tag}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
使用:
<TextBox Style="{StaticResource TaggedTextBox}" Tag="Cheese" Text="Spaghetti"/>
看:
如果您使用的是 mahapps.metro version >= 2.0
则执行此操作:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:Double x:Key="MahApps.Font.Size.FloatingWatermark">15</sys:Double>
</ResourceDictionary>
如果您的 mahapps.metro version < 2.0
是:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:Double x:Key="FloatingWatermarkFontSize">15</sys:Double>
</ResourceDictionary>
如何在下面的 WPF 代码中增加水印文本的字体大小('8 小时'):
<TextBox x:Name="txt8HoursArm1"
Margin="5"
Grid.Column="1"
IsTabStop="False"
Style="{StaticResource PrimaryInputTextBoxStyle}"
Controls:TextBoxHelper.UseFloatingWatermark="True"
Controls:TextBoxHelper.Watermark="8 Hours"
IsEnabled="False"
Text="1"
GotFocus="txt_GotFocus"
PreviewTextInput="txt_PreviewTextInput"
TextChanged="txt_TextChanged" FontSize="14" />
请看下图的文本框
或者您可以创建自己的风格,完全控制一切:
<Style x:Key="TaggedTextBox" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="Hotpink"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Height" Value="32"/>
<Setter Property="FontSize" Value="15" />
<Setter Property="FontFamily" Value="Arial" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid>
<TextBox HorizontalContentAlignment="Left" Text="{TemplateBinding Text}" Background="{TemplateBinding Background}" VerticalContentAlignment="Bottom" Foreground="{TemplateBinding Foreground}" FontSize="{TemplateBinding FontSize}" />
<TextBlock Foreground="Lime" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="10" Margin="5,2" Text="{TemplateBinding Tag}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
使用:
<TextBox Style="{StaticResource TaggedTextBox}" Tag="Cheese" Text="Spaghetti"/>
看:
如果您使用的是 mahapps.metro version >= 2.0
则执行此操作:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:Double x:Key="MahApps.Font.Size.FloatingWatermark">15</sys:Double>
</ResourceDictionary>
如果您的 mahapps.metro version < 2.0
是:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:Double x:Key="FloatingWatermarkFontSize">15</sys:Double>
</ResourceDictionary>