Skip to content

Conversation

Dotnetifier
Copy link
Contributor

Adds the Floating Watermark feature.

Add Controls:TextboxHelper.UseFloatingWatermark="True" to a TextBox/PasswordBox with a watermark and it will appear when there is text in the box. The foreground color will be the box's, unless the box is focused, then it will have the Foreground brush set to AccentColorBrush.

Closes #1318. Includes an edited fix for #1343, triggers the show of the floating watermark when the box already has text/a password.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to tell what you've fixed in a comment, this should be in the commit message so that everyone can see it ;)

@mrahhal
Copy link
Contributor

mrahhal commented Aug 19, 2014

@Dotnetifier you should ditch the AnimtionUsingKeyFrames thing, a normal animation with an easing function is much more better visually.
Also the Storyboards are duplicated, we can share them in single .xaml and merge it into the TextBox.xaml and PasswordBox.xaml.
I'm making a PR on your fork. Review it and tell me what you think.
Please update the title to mention "[WIP]" first so that the maintainers know we're not ready for a merge yet.

@Dotnetifier Dotnetifier changed the title Added the Floating Watermark feature [WIP] Added the Floating Watermark feature Aug 19, 2014
@Dotnetifier
Copy link
Contributor Author

This AnimationUsingKeyFrames matches the Windows 8 easing function more closely than any (built-in) easing function I have seen. I do agree it would look better if it uses an easing function. Is there a possibility we could convert the KeySpline into an easing function?

@mrahhal
Copy link
Contributor

mrahhal commented Aug 19, 2014

@Dotnetifier I'm working on that right now. I know it matches Windows 8 style, though we're talking functionally. What I mean is that you can never match Windows 8 style as efficiently as Windows 8. Windows 8 animations require direct control of the underlying system (which it does). In WPF, all you get while trying to match that in "small change" animations is a jerky last change in position. I'm sure you can see that.

Flyouts work well with KeySplines since it's a big control, here we're talking about the floating text which is small, and because of that mimicking Windows 8 style is not efficient.

If you're thinking about matching the behavior using an easing function, even if you can, the jerkiness will still be there.

A normal animation with a normal (perhaps Exponential) easing function is more efficient, and apparently, is more attractive visually in my tests (no jerkiness).
Of course, after I make the PR on your fork, if you don't like it you can always revert to using KeyFrames. Personally, I never use KeyFrames in such cases.

mrahhal and others added 4 commits August 19, 2014 19:41
Changed the whole storyboards.
Moved the storyboards to Shared.xaml, to share them in both TextBox.xaml
and PasswordBox.xaml.
Some editions to the floating watermak
@Dotnetifier
Copy link
Contributor Author

@mrahhal Everything here is working correctly now. Thanks!

@Dotnetifier Dotnetifier changed the title [WIP] Added the Floating Watermark feature Added the Floating Watermark feature Aug 19, 2014
@mrahhal
Copy link
Contributor

mrahhal commented Aug 19, 2014

Latest behavior.
mahapps-floating-message2

@mrahhal
Copy link
Contributor

mrahhal commented Aug 19, 2014

@Dotnetifier Nice work.
@flagbug @punker76 Ready to merge.

@flagbug
Copy link
Member

flagbug commented Aug 19, 2014

@mrahhal Cool, but I'll leave this for the next version.

0.14 is basically finished and I don't want to introduce any new features that close before release.

@mrahhal
Copy link
Contributor

mrahhal commented Aug 19, 2014

Not a problem. Just letting you know that it's finished.

@flagbug flagbug added this to the v1.0 milestone Aug 20, 2014
@laicasaane
Copy link

Great! Should it expose a property to change the floating watermark's font size? I see you hardcoded it, and the opacity as well.

@Dotnetifier
Copy link
Contributor Author

@Tyelpion Changing the font size might be useful, but a fixed text height is needed for the animation. It isn't possible to animate to NaN or Auto or something similar. It's possible to animate the MaxHeight, but you'd always have a maximum value.

I just picked an opacity value that looked good, so I don't know if that should be changed. It's always nice to have an option, however.

@thoemmi
Copy link
Collaborator

thoemmi commented Sep 2, 2014

Font sized are declared in Fonts.xaml. Please either reuse an existing size, add the size for the watermark to that file, or use a converter (e.g. FontSizeOffsetConverter) to base your size on another one.

@laicasaane
Copy link

At first I was very fond of this control. But after doing some test, I've felt that it really needs another approach to the font size problem. Also, expanding textbox is pretty lovely, but the layout structure will become unpredictable, or be broken sometimes. Could you implement a style that retains the original design? Without expansion, and the floating label can be scaled based on the text size, or it can be changed separately?

@Dotnetifier
Copy link
Contributor Author

I see your point. I put the font size in Fonts.xaml (not committed yet), which does allow for easier customization, but it would be easier to make another attached property in TextboxHelper. Implementing something that calculates a font size would not be suitable for every font size.

About the original design (also includes this): the floating message goes above the text, not the bounding box. That is not really visible for those controls since there is already some empty space above and they have no border. I tried to make the watermark float above the TextBox, but I thought it looked hideous because of the border and it was overlapping other controls. Another option is to make a fixed height TextBox. Then it will look like this:
screencapture_5-9-2014_21

@laicasaane
Copy link

Thanks for your work and explanation, I can see it's really complicated. However, I just realized that what I talked about should be a new control, while what you are working on is making floating labels for the pure Textbox. I feel so sorry for unnecessary problems you have had to think of due to my ignorance about your idea!

@Dotnetifier
Copy link
Contributor Author

That's fine! You were right about the font size, that should have been in the Fonts.xaml indeed.

@amkuchta
Copy link
Contributor

@flagbug @punker76 Any ideas on when this may be merged into a pre-release? I am very interested in implementing this feature in my application (no rush, just curious / excited).

@flagbug
Copy link
Member

flagbug commented Oct 13, 2014

I'll review this now and merge it if everything works, sorry for the delay

flagbug added a commit that referenced this pull request Oct 13, 2014
Added the Floating Watermark feature
@flagbug flagbug merged commit 94f2605 into MahApps:master Oct 13, 2014
@flagbug
Copy link
Member

flagbug commented Oct 13, 2014

@Dotnetifier Thanks for that feature!

A new NuGet package should come through the build server in a few minutes

@amkuchta
Copy link
Contributor

@flagbug I never saw an updated package come through NuGet; any ideas why?

@flagbug
Copy link
Member

flagbug commented Oct 14, 2014

@amkuchta Are you on the prerelease channel?

@amkuchta
Copy link
Contributor

I am, and when I went in to update, there was not updated version of the package available

@amkuchta
Copy link
Contributor

@flagbug ^^

@flagbug
Copy link
Member

flagbug commented Oct 14, 2014

@amkuchta Can you try it again? I just merged some other things and the build server just pushed https://www.nuget.org/packages/MahApps.Metro/0.15.0-ALPHA43

@amkuchta
Copy link
Contributor

@flagbug still no joy; I tried updating via both the package manager console and the "Manage NuGet Packages" GUI

@amkuchta
Copy link
Contributor

@flagbug scratch that; I did a clean uninstall and install, it worked. The update just would not pull down.

@amkuchta
Copy link
Contributor

@Dotnetifier Is there any way to still use the resizable textbox when using the floating watermark, or is the fixed-height the only way forward?

@Dotnetifier
Copy link
Contributor Author

@amkuchta You can use the non-fixed height TextBox. I would place the Auto height TextBox in a StackPanel or some other auto positioning container. You might want to see the text examples in MetroDemo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

6 participants