wpf-devexpress-dot-xpf-dot-richedit-dot-richeditcontrol-d3c0845d.md
Occurs when the EncryptionPassword property is not set or returns an invalid password.
Namespace : DevExpress.Xpf.RichEdit
Assembly : DevExpress.Xpf.RichEdit.v25.2.dll
NuGet Package : DevExpress.Wpf.RichEdit
public event EncryptedFilePasswordRequestedEventHandler EncryptedFilePasswordRequested
Public Event EncryptedFilePasswordRequested As EncryptedFilePasswordRequestedEventHandler
The EncryptedFilePasswordRequested event's data class is EncryptedFilePasswordRequestedEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Cancel | Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs. |
| DocumentName | Gets the name of the encrypted document. |
| Password | Gets or sets the password used to encrypt the document. |
The EncryptedFilePasswordRequested event allows you to specify a password in code using the Password property. If the given password is empty or invalid, the EncryptedFilePasswordCheckFailed event raises.
View Example: Document Encryption (Simple Example)
int tryCount = 4;
private void RichEditControl1_EncryptedFilePasswordRequested(object sender, EncryptedFilePasswordRequestedEventArgs e)
{
//Count the amount of attempts to enter the password
if (tryCount > 0)
{
tryCount--;
}
}
private void RichEditControl1_EncryptedFilePasswordCheckFailed(object sender, EncryptedFilePasswordCheckFailedEventArgs e)
{
//Analyze the error led to this event
switch (e.Error)
{
case RichEditDecryptionError.PasswordRequired:
if (tryCount > 0)
{
e.TryAgain = true;
e.Handled = true;
System.Windows.Forms.MessageBox.Show("You did not enter the password!", String.Format("{0} attempts left", tryCount));
}
else
e.TryAgain = false;
break;
case RichEditDecryptionError.WrongPassword:
if (tryCount > 0)
{
if (System.Windows.Forms.MessageBox.Show("The password is incorrect. Try Again?", string.Format("{0} attempts left", tryCount),
MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
{
e.TryAgain = true;
e.Handled = true;
}
}
break;
}
}
Private tryCount As Integer = 4
Private Sub RichEditControl1_EncryptedFilePasswordRequested(ByVal sender As Object, ByVal e As EncryptedFilePasswordRequestedEventArgs)
'Count the amount of attempts to enter the password
If tryCount > 0 Then
tryCount -= 1
End If
End Sub
Private Sub RichEditControl1_EncryptedFilePasswordCheckFailed(ByVal sender As Object, ByVal e As EncryptedFilePasswordCheckFailedEventArgs)
'Analyze the error led to this event
Select Case e.[Error]
Case RichEditDecryptionError.PasswordRequired
If tryCount > 0 Then
e.TryAgain = True
e.Handled = True
System.Windows.Forms.MessageBox.Show("You did not enter the password!", String.Format("{0} attempts left", tryCount))
Else
e.TryAgain = False
End If
Case RichEditDecryptionError.WrongPassword
If tryCount > 0 Then
If System.Windows.Forms.MessageBox.Show("The password is incorrect. Try Again?", String.Format("{0} attempts left", tryCount), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = System.Windows.Forms.DialogResult.Yes Then
e.TryAgain = True
e.Handled = True
End If
End If
End Select
End Sub
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the EncryptedFilePasswordRequested event.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
wpf-richedit-document-encryption/CS/DXRichEdit_Encryption/MainWindow.xaml#L41
DocumentSource="{Binding Path=RichEditDocumentSource}"
EncryptedFilePasswordRequested="RichEditControl1_EncryptedFilePasswordRequested"
EncryptedFilePasswordCheckFailed="RichEditControl1_EncryptedFilePasswordCheckFailed"
See Also