WPF use RadPasswordBox in RadGridView

1 Answer 18 Views
GridView
Scott Waye
Top achievements
Rank 1
Veteran
Scott Waye asked on 26 May 2021, 07:12 PM

Is this possible?  I have a custom column:


public class GridViewPasswordColumn : GridViewBoundColumnBase
    {
		public GridViewPasswordColumn()
		{
			EditTriggers = GridViewEditTriggers.CellClick;
		}

        public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
        {
            return new TextBlock {Text = "**********"};
        }

        public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)
		{
			var picker = new RadPasswordBox();
			return picker;
		}

        public override object GetNewValueFromEditor(object editor)
		{
            RadPasswordBox passwordBox = editor as RadPasswordBox;
            return passwordBox.Password;
        }
}

 

Which I use in the xaml:

 


			<thcg:GridView  ItemsSource="{Binding Users}" CanUserInsertRows="True" NewRowPosition="Top" 
						 AutoGenerateColumns="False" hse:GridBindingHelper.ComboColumnBinder="{Binding BusinessUnitBinders}" >
				<tkg:RadGridView.Columns>
                     <thcg:GridViewPasswordColumn Header="Password" DataMemberBinding="{Binding PasswordClear}" MinWidth="100" UniqueName="colPassword" >
                    </thcg:GridViewPasswordColumn>

However the setting for PasswordClear is never called.  What am I doing wrong?

 

Thanks

1 Answer, 1 is accepted

Sort by
1
Accepted
Vladimir Stoyanov
Telerik team
answered on 31 May 2021, 10:53 AM

Hello Scott,

Thank you for the shared code snippets.

When creating a custom column editor, you are responsible for connecting the desired property of the editor with a property from the model. Since the Password and SecurePassword properties are not DependencyProperties for security reasons, you can manually transfer the value to the property in the model. 

I am attaching a sample project demonstrating a possible approach for doing so in the GetNewValueFromEditor method. Please, check it out and let me know, if it helps.

Regards,
Vladimir Stoyanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Scott Waye
Top achievements
Rank 1
Veteran
commented on 31 May 2021, 01:34 PM

Thanks, that looks good.
Tags
GridView
Asked by
Scott Waye
Top achievements
Rank 1
Veteran
Answers by
Vladimir Stoyanov
Telerik team
Share this question
or