New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Changing font style for watermark #2491

Closed
deejay220989 opened this Issue May 7, 2016 · 7 comments

Comments

Projects
None yet
5 participants
@deejay220989

deejay220989 commented May 7, 2016

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

This comment has been minimized.

Member

punker76 commented May 10, 2016

@deejay220989 This is currently not possible.

@deejay220989

This comment has been minimized.

deejay220989 commented May 11, 2016

Thanks for the response :)

@Dotnetifier

This comment has been minimized.

Contributor

Dotnetifier commented May 23, 2016

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

@punker76 punker76 self-assigned this Jun 16, 2016

@punker76 punker76 added this to the 1.4.0 milestone Jul 7, 2016

@punker76 punker76 modified the milestones: 1.5.0, 1.4.0 Dec 21, 2016

@punker76 punker76 modified the milestones: 1.6.0, 1.5.0 Apr 12, 2017

@punker76 punker76 closed this in 433eec3 May 18, 2017

@punker76

This comment has been minimized.

Member

punker76 commented May 18, 2017

@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 punker76 removed the Enhancement label Feb 11, 2018

@trtrifonov

This comment has been minimized.

trtrifonov commented Sep 19, 2018

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 ?

@wojiaofsp

This comment has been minimized.

wojiaofsp commented Sep 19, 2018

@trtrifonov

This comment has been minimized.

trtrifonov commented Sep 19, 2018

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment