How Can i make a MaterialdesignFloatingHintTextBox's Hint to always float at the top in WPF C#

Mesh Ka 345 Reputation points
2023-12-04T13:39:48.33+00:00

How can i make a materialdesignFloatingHintTextBox's hint property always float at the top of the textbox regardless of where the textbox is empty or not.

Here is my Project with no Code Behind

XAML;

<Window x:Class="MaterialDesignFixedHintTextBox.MainWindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"         xmlns:local="clr-namespace:MaterialDesignFixedHintTextBox"         xmlns:materialdesign="http://materialdesigninxaml.net/winfx/xaml/themes"         mc:Ignorable="d"         Title="MainWindow" Height="450" Width="800">     <Window.Resources>         <ResourceDictionary>             <ResourceDictionary.MergedDictionaries>                 <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml"/>                 <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml"/>                 <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Green.xaml"/>                 <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml"/>             </ResourceDictionary.MergedDictionaries>              <Style x:Key="NameTextBox" TargetType="TextBox" BasedOn="{StaticResource MaterialDesignFloatingHintTextBox}">                 <Setter Property="materialdesign:HintAssist.HintOpacity" Value="0.90"/>                 <Setter Property="materialdesign:HintAssist.IsFloating" Value="False"/>                 <Setter Property="materialdesign:ColorZoneAssist.Mode" Value="Dark"/>                 <Setter Property="materialdesign:HintAssist.HintOpacity" Value="0.10"/>                 <Setter Property="materialdesign:HintAssist.FontFamily" Value="Century Gothic"/>                 <Setter Property="Foreground" Value="AliceBlue"/>                 <Setter Property="FontSize" Value="20"/>             </Style>         </ResourceDictionary>     </Window.Resources>      <Grid>         <Grid.Background>             <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">                 <GradientStop Color="#FF06013F" Offset="1"/>                 <GradientStop Color="#FF040F2E"/>             </LinearGradientBrush>         </Grid.Background>         <StackPanel Margin="30" Orientation="Horizontal" Height="80">             <TextBox Style="{StaticResource NameTextBox}" Width="100" materialdesign:HintAssist.Hint="FirstName" Margin="0 0 50 0"                      VerticalAlignment="Bottom"/>         </StackPanel>     </Grid> </Window> 
Developer technologies | Windows Presentation Foundation
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Hui Liu-MSFT 48,676 Reputation points Microsoft External Staff
    2023-12-05T05:34:43.7066667+00:00

    Hi,@Mesh Ka . Welcome to Microsoft Q&A Forum.

    I don't think you could do that currently. Looking at this part of the SmartHint in MaterialDesignThemes, it seems that it very much depends on focus and non-emptyness. This code sets the visual state which triggers the transition (i.e. animation) that levitates/floats the hint.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.