新问题。
我在可以编辑的数据网格中显示信息。但是,其中一列是数据库中的密码字段。是否可以像密码文本框控件一样屏蔽显示给用户的文本?这是网格的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>
谢谢。
答案 0 :(得分: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;
}
}