How to add an icon inside a Textbox using Material Design?

Asked

Viewed 95 times

0

I installed the Material Design Xaml package in my project, but I have a question of how to create an icon in Textbox.

I have the following code:

<StackPanel>
  <TextBox
    Style="{StaticResource MaterialDesignFilledTextFieldTextBox}"
    VerticalAlignment="Top"
    AcceptsReturn="True"
    TextWrapping="Wrap"
    MaxWidth="400"
    materialDesign:HintAssist.Hint="Test">
 </TextBox>
    <materialDesign:PackIcon Margin="0,-50,0,0" Kind="User" Foreground="#3e4147" Height="50" Width="50"/>
</StackPanel>

but it doesn’t work, I try to do the same image below

inserir a descrição da imagem aqui

1 answer

1


Use the Canvas, as it allows moving the elements to any corner.

Use the padding in his textbox to leave a space on the left side.

It is important to leave the materialDesign on the top line to overlap the textbox

<Canvas>
    <materialDesign:PackIcon Kind="Heart" Foreground="#3e4147" Height="30" Width="30" Canvas.Left="156" Canvas.Top="34"/>
    <TextBox
        Padding="34 0 0 0"
        Style="{StaticResource MaterialDesignFilledTextFieldTextBox}"
        VerticalAlignment="Top"
        AcceptsReturn="True"
        TextWrapping="Wrap"
        MaxWidth="400"
        materialDesign:HintAssist.Hint="Label" Width="451" Canvas.Left="147" Canvas.Top="10"/>
</Canvas>

The end result will be this:

inserir a descrição da imagem aqui

  • Thanks for the tips, really Canvas helped a lot, I’m starting now in WPF have some good wiki to follow taking away from microsoft ?

  • 1

    I really like this site https://www.wpf-tutorial.com/Localization/LanguageStatus/pt/ it explains all the elements and what each one does

Browser other questions tagged

You are not signed in. Login or sign up in order to post.