namespace VideoBrowser.Controls.CefSharpBrowser { using System.Collections.ObjectModel; using System.Windows; using System.Windows.Input; using VideoBrowser.Common; using VideoBrowser.Controls.CefSharpBrowser.AddIns; /// /// Interaction logic for UrlTextBox.xaml. /// public partial class UrlTextBox { #region Fields public static readonly DependencyProperty AddInButtonClickedProperty = DependencyProperty.Register(nameof(AddInButtonClicked), typeof(ICommand), typeof(UrlTextBox), new PropertyMetadata(null)); public static readonly DependencyProperty LeftAddInButtonsProperty = DependencyProperty.Register(nameof(LeftAddInButtons), typeof(ObservableCollection), typeof(UrlTextBox), new PropertyMetadata()); public static readonly DependencyProperty NavigateUrlCommandProperty = DependencyProperty.Register(nameof(NavigateUrlCommand), typeof(ICommand), typeof(UrlTextBox), new PropertyMetadata(null)); public static readonly DependencyProperty NavigateUrlProperty = DependencyProperty.Register(nameof(NavigateUrl), typeof(string), typeof(UrlTextBox), new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnNavigateUrlChanged)); public static readonly DependencyProperty RightAddInButtonsProperty = DependencyProperty.Register(nameof(RightAddInButtons), typeof(ObservableCollection), typeof(UrlTextBox), new PropertyMetadata()); public static readonly DependencyProperty UrlProperty = DependencyProperty.Register(nameof(Url), typeof(string), typeof(UrlTextBox), new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnUrlChanged)); #endregion Fields #region Constructors /// /// Initializes a new instance of the class. /// public UrlTextBox() { this.BookmarkAddIn = new BookmarkAddIn(); this.IsSecureAddIn = new IsSecureAddIn(); this.InternalNavigateUrlCommand = new RelayCommand(this.OnNavigateUrl, nameof(this.InternalNavigateUrlCommand)); this.InitializeComponent(); this.LeftAddInButtons = new ObservableCollection { this.IsSecureAddIn }; this.RightAddInButtons = new ObservableCollection { this.BookmarkAddIn }; this.TextBox.InputBindings.Add(new KeyBinding(this.InternalNavigateUrlCommand, Key.Enter, ModifierKeys.None)); this.GotFocus += this.OnUrlTextBox_GotFocus; } #endregion Constructors #region Properties /// /// Gets or sets the AddInButtonClicked. /// public ICommand AddInButtonClicked { get { return (ICommand)GetValue(AddInButtonClickedProperty); } set { SetValue(AddInButtonClickedProperty, value); } } /// /// Gets the BookmarkAddIn. /// public BookmarkAddIn BookmarkAddIn { get; } /// /// Gets the IsSecureAddIn. /// public IsSecureAddIn IsSecureAddIn { get; } /// /// Gets or sets the LeftAddInButtons. /// public ObservableCollection LeftAddInButtons { get => (ObservableCollection)GetValue(LeftAddInButtonsProperty); set => SetValue(LeftAddInButtonsProperty, value); } /// /// Gets or sets the NavigateUrl. /// public string NavigateUrl { get => (string)GetValue(NavigateUrlProperty); set => SetValue(NavigateUrlProperty, value); } /// /// Gets or sets the NavigateUrlCommand. /// public ICommand NavigateUrlCommand { get => (ICommand)GetValue(NavigateUrlCommandProperty); set => SetValue(NavigateUrlCommandProperty, value); } /// /// Gets or sets the RightAddInButtons. /// public ObservableCollection RightAddInButtons { get => (ObservableCollection)GetValue(RightAddInButtonsProperty); set => SetValue(RightAddInButtonsProperty, value); } /// /// Gets or sets the Url. /// public string Url { get => (string)GetValue(UrlProperty); set => SetValue(UrlProperty, value); } /// /// Gets the InternalNavigateUrlCommand. /// private ICommand InternalNavigateUrlCommand { get; } #endregion Properties #region Methods /// /// The OnNavigateUrlChanged. /// /// The d. /// The e. private static void OnNavigateUrlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var textBox = (UrlTextBox)d; var navigateUrl = e.NewValue.ToString(); textBox.BookmarkAddIn.Url = navigateUrl; textBox.IsSecureAddIn.Url = navigateUrl; textBox.Url = navigateUrl; } /// /// The OnUrlChanged. /// /// The d. /// The e. private static void OnUrlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var textBox = (UrlTextBox)d; textBox.BookmarkAddIn.Url = string.Empty; textBox.IsSecureAddIn.Url = string.Empty; } /// /// The OnNavigateUrl. /// /// The obj. private void OnNavigateUrl(object obj) { this.BookmarkAddIn.Url = this.Url; this.IsSecureAddIn.Url = this.Url; this.NavigateUrlCommand?.Execute(obj); } /// /// The OnUrlTextBox_GotFocus. /// /// The sender. /// The e. private void OnUrlTextBox_GotFocus(object sender, RoutedEventArgs e) { this.TextBox.Focus(); } #endregion Methods } }