D
D
Dmitry Olshak2017-06-12 00:26:57
WPF
Dmitry Olshak, 2017-06-12 00:26:57

How to hide password in gridview?

I need to hide password cells on datagrid with characters *
I'm using MVVM approach so store ObservableCollection Records in viewmodel.
I have two options:
1. Use a converter when binding the itemsource to the collection, but in that case the new entry does not hide the password.
2. Create a collection of columns in the datagrid and, when linking the column to the corresponding field of the Record class, apply the converter. I created one column for experimentation, the new entry now hides the data behind the characters, however there is a duplication of the columns. I don't know how to fix this.
I ask for your advice, dear programmers!
An example datagrid code using two options:

<!--Первый вариант-->
        <DataGrid ItemsSource="{Binding Records, Converter={StaticResource PassConverter}}" 
                  BorderThickness="0,2,0,0"
                  ColumnWidth="*" 
                  CanUserResizeColumns="False" 
                  CanUserAddRows="False" 
                  CanUserDeleteRows="False" 
                  CanUserResizeRows="False" 
                  IsReadOnly="True"
                  SelectedIndex="{Binding CurrentIndexOfRecord}">
            <DataGrid.Columns>
                <!--Второй вариант-->
                <DataGridTextColumn Header="Login" Binding="{Binding Path=Login, Converter={StaticResource FieldPassConverter}}" />
            </DataGrid.Columns>

Result:
182fc9bc1bc4446b85d3812caa5e84a5.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Olshak, 2017-06-12
@dmitry_olshak

The answer was found.
I will use the second option. And so that the columns are not duplicated in the datagrid, you need to set
the AutoGenerateColumns property to False.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question