Question: Changing font style for watermark
Hi all,
I'm using TextBoxHelper Watermark, and I would like to change the style. I prefer my watermark to be les bold and italic. How can I do that?
Environment
- MahApps.Metro v1.2.4
- Windows 8
- Visual Studio 2015 Update 2
- .NET Framework 4.0
@deejay220989 This is currently not possible.
Thanks for the response :)
Well it is possible to change the font size of the floating watermark. The style for the floating watermark TextBlock is defined here and it uses FloatingWatermarkFontSize for the font size. You can override that resource value in your own code:
First add xmlns:sys="clr-namespace:System;assembly=mscorlib" as an attribute, then add the following to an element using the floating watermark or any panel containing those elements:
<FrameworkElement.Resources>
<sys:Double x:Key="FloatingWatermarkFontSize">14</sys:Double>
</FrameworkElement.Resources>
A lot of things may be off since it isn't officially supported I guess, but the styles might be modified so that they can be used this way (or ControlHelper.FloatingWatermarkStyle should be added).
@deejay220989 With 1.6.0 you can now override all Watermarks with this style
<Style x:Key="MahApps.Metro.Styles.MetroWatermarkTextBlock"
BasedOn="{StaticResource MetroTextBlock}"
TargetType="{x:Type TextBlock}">
<Setter Property="IsHitTestVisible" Value="False" />
<Setter Property="Opacity" Value="0.6" />
</Style>
Hello,
I was able to use this code - I can set Opacity, FontSize, Background to the watermark of a TextBox. But I can not set Foreground for the watermark. Is this possible? What is want is to have a watermark with a green Foreground , while the TextBox will have default Foreground.
I checked the source code of MahApps.Metro and suppose it is not possible. I think it takes always the Foreground of the TextBox. Is it trie ?
修改源代码再编译。 modify src code,then built it
在 2018年9月19日,15:21,buba4ko [email protected] 写道:
Hello,
I was able to use this code - I can set Opacity, FontSize, Background to the watermark of a TextBox. But I can not set Foreground for the watermark. Is this possible?
I checked the source code of MahApps.Metro and suppose it is not possible. I think it takes always the Foreground of the TextBox. Is it trie ?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
I did this by workaround - set green foreground to the TextBox when the Text value is empty, which actually sets the foreground of the watermark :) But I would be glad if there is a official solution. I do not want to edit the source code of the MahApps. When I get a new version then modify again? Here is my code, in case someone needs it:
<Style x:Key="MahApps.Metro.Styles.MetroWatermarkTextBlock" BasedOn="{StaticResource MetroTextBlock}" TargetType="{x:Type TextBlock}">
<Setter Property="IsHitTestVisible" Value="False" />
<Setter Property="Opacity" Value="0.5" />
</Style>
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Style.Triggers>
<Trigger Property="Text" Value="">
<Setter Property="Foreground" Value="Green" />
</Trigger>
</Style.Triggers>
</Style>