123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Runtime.CompilerServices;
- using System.Windows;
- using System.Windows.Controls;
- namespace ComPDFKit.Controls.PDFControl
- {
- public partial class SetEncryptionControl : UserControl, INotifyPropertyChanged
- {
- private bool _isUserPasswordEnabled;
- public bool IsUserPasswordEnabled
- {
- get => _isUserPasswordEnabled;
- set
- {
- _isUserPasswordEnabled = value;
- OnPropertyChanged();
- UpdateValidation();
- }
- }
- private bool _isOwnerPasswordEnabled;
- public bool IsOwnerPasswordEnabled
- {
- get => _isOwnerPasswordEnabled;
- set
- {
- _isOwnerPasswordEnabled = value;
- OnPropertyChanged();
- UpdateValidation();
- }
- }
-
- private string _userPassword;
- public string UserPassword
- {
- get => _userPassword;
- set
- {
- _userPassword = value;
- OnPropertyChanged();
- UpdateValidation();
- }
- }
-
- private string _ownerPassword;
- public string OwnerPassword
- {
- get => _ownerPassword;
- set
- {
- _ownerPassword = value;
- OnPropertyChanged();
- UpdateValidation();
- }
- }
-
- private bool _isAllowPrint = true;
- public bool IsAllowPrint
- {
- get => _isAllowPrint;
- set
- {
- _isAllowPrint = value;
- OnPropertyChanged();
- }
- }
-
- private bool _isAllowCopy = true;
- public bool IsAllowCopy
- {
- get => _isAllowCopy;
- set
- {
- _isAllowCopy = value;
- OnPropertyChanged();
- }
- }
-
- private int _cryptographicLevel;
- public int CryptographicLevel
- {
- get => _cryptographicLevel;
- set
- {
- _cryptographicLevel = value;
- OnPropertyChanged();
- }
- }
- public static readonly DependencyProperty IsEnsureProperty =
- DependencyProperty.Register(nameof(IsSettingValid), typeof(bool), typeof(SetEncryptionControl), new PropertyMetadata(false));
- public bool IsSettingValid
- {
- get => (bool)GetValue(IsEnsureProperty);
- private set => SetValue(IsEnsureProperty, value);
- }
-
-
- public event PropertyChangedEventHandler PropertyChanged;
-
- public SetEncryptionControl()
- {
- InitializeComponent();
- DataContext = this;
- }
-
- private void UpdateValidation()
- {
- if (!IsOwnerPasswordEnabled && !IsUserPasswordEnabled)
- {
- IsSettingValid = false;
- return;
- }
- bool validUserOption = !IsUserPasswordEnabled || !string.IsNullOrEmpty(UserPassword);
- bool validOwnerOption = !IsOwnerPasswordEnabled || !string.IsNullOrEmpty(OwnerPassword);
- IsSettingValid = validUserOption && validOwnerOption;
- }
-
- protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- }
- }
|