0

Hello i need create part of my table be like passwordbox(I mean, text must be hide using for example *)

This is part of my table

                      <GridViewColumn Header="Password" Width="80">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock HorizontalAlignment="Center" Text="{Binding Path=Password}"  Foreground="Black"></TextBlock>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

when i will add for example "cat", i will get explicit cat but i want get ***, and then if i will referred to this part of table i want to get this 'cat'

thx for help

dybleG
  • 51
  • 1
  • 10
  • You can use a converter instead of `Text="{Binding Path=Password}"`, that returns a string of equal length with the Bound string. – Lupu Silviu Nov 18 '16 at 16:06

1 Answers1

0

Why not display fixed amount of stars for each row? This way you are not revealing information like password length. Does it really matter if number of stars equals password's length when you are never showing it?

<TextBlock HorizontalAlignment="Center" Text="****"  Foreground="Black"></TextBlock>

In case you need length to match then write similar converter:

public class StarsConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == null) return null;
        var paswordLength = (value as string).Length;
        var symbol = (parameter ?? "*").ToString().First();
        return new string(symbol, paswordLength);
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

in XAML you can provide additional parameter with symbol which is used to display password, but it will default to *

 <TextBlock Text="{Binding pass,Converter={StaticResource ResourceKey=passConverter},ConverterParameter=^}" />
lukbl
  • 1,763
  • 1
  • 9
  • 13