Question

New problem.

I am showing information in a Data Grid that can be edited. However, one of the columns is a Password field from the Database. Is it possible to mask the text shown to the User much like the Password Text Box control? This is the XAML for the grid: (The column I am referring to is the Credentials column)

 <sdk:DataGrid x:Name="grdApplications" 
                              HorizontalAlignment="Left" 
                              Height="570" Margin="10,39,0,0"
                              VerticalAlignment="Top" 
                              Width="1132" 
                              AlternatingRowBackground="#FFB4CDCD" 
                              AutoGenerateColumns="False" 
                              ItemsSource="{Binding Data, ElementName=Apps}" >
                    <sdk:DataGrid.Columns>
                        <sdk:DataGridTemplateColumn Header="Name">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate x:Name="appTemplate">
                                    <HyperlinkButton Content="{Binding Name}" 
                                                     HorizontalAlignment="Left" 
                                                     VerticalAlignment="Center"
                                                     Foreground="#2020F0"
                                                     Click="lnkEditApp_Click" />
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                        <sdk:DataGridTextColumn Header="Require Authentication?" Binding="{Binding Type}" />
                        <sdk:DataGridTextColumn Header="User ID" Binding="{Binding Data}" />
                        <sdk:DataGridTextColumn Header="Retry Count" Binding="{Binding Binding}" />
                        <sdk:DataGridTextColumn Header="Credentials" Binding="{Binding Url}" />
                    </sdk:DataGrid.Columns>
                </sdk:DataGrid>

Thank you.

Was it helpful?

Solution

Do you need to retrieve the password back or is it just for display ?

If it so you can try a converter :

 <sdk:DataGridTextColumn Header="Credentials" Binding="{Binding Url, Converter={StaticResource MyConverterReference}}" />

 <Grid.Resources>
    <c:MyConverter x:Key="MyConverterReference"/>
 </Grid.Resources>

Coupling with :

 public class MyConverter : IValueConverter
 {
    public object Convert(object o, Type type,object parameter, CultureInfo culture)
    {
      string objectToConvert = o.ToString();
      var secure = new SecureString();

      foreach (char c in objectToConvert )
      {
        secure.AppendChar(c);
      }

      return secure;
    }

    public object ConvertBack(object o, Type type,object parameter, CultureInfo culture)
    {
      return null;
    }
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top