MahApps.Metro icon indicating copy to clipboard operation
MahApps.Metro copied to clipboard

Question: Changing font style for watermark

Open deejay220989 opened this issue 10 years ago • 7 comments

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 avatar May 07 '16 01:05 deejay220989

@deejay220989 This is currently not possible.

punker76 avatar May 10 '16 07:05 punker76

Thanks for the response :)

deejay220989 avatar May 11 '16 09:05 deejay220989

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).

Dotnetifier avatar May 23 '16 11:05 Dotnetifier

@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>

punker76 avatar May 18 '17 13:05 punker76

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 ?

trtrifonov avatar Sep 19 '18 07:09 trtrifonov

修改源代码再编译。 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.

wojiaofsp avatar Sep 19 '18 07:09 wojiaofsp

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>

trtrifonov avatar Sep 19 '18 08:09 trtrifonov