1

新问题。

我在可以编辑的数据网格中显示信息。但是,其中一列是数据库中的密码字段。是否可以像密码文本框控件一样屏蔽显示给用户的文本?这是网格的 XAML:(我指的是 Credentials 列)

 <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>

谢谢你。

4

1 回答 1

3

您需要找回密码还是只是为了显示?

如果是这样,您可以尝试使用转换器:

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

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

耦合:

 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;
    }
 }
于 2013-04-24T08:33:16.277 回答