diff --git a/Changelog.md b/Changelog.md index 35b58cf6f..3ed27d521 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,7 +3,9 @@ ## 5.0.0 (preview) - ### Breaking changes - - Office 2010 and Windows 8 themes got removed. Office 2013 theme was moved from Themes/Office2013/Generic.xaml to Themes/Generic.xaml. This was a [community voted decision](../../issues/282). + - Office 2010 and Windows 8 themes got removed. + Office 2013 theme was moved from "Themes/Office2013/Generic.xaml" to "Themes/Generic.xaml". + This was a [community voted decision](../../issues/282). - [#301](../../issues/301) - Remove Office 2010 and Windows 8 themes - [#302](../../issues/302) - Rename Office 2013 theme to Generic - [#309](../../issues/309) - Remove grouping from ComboBox and make GalleryPanel inherit from StackPanel @@ -24,7 +26,8 @@ - [#279](../../issues/279) - Localization of ColorGallery - [#299](../../issues/299) - Quick access items should show item text as tool tip if no tooltip is set - [#324](../../issues/324) - Add "IsSeparatorVisible" to RibbonGroupBox (thanks to @maurosampietro) - - [#326](../../issues/326) - Add interface for controls which provide LargeIcon + - [#326](../../issues/326) - Add interface for controls which provide LargeIcon + - [#334](../../issues/334) - Select all text in Spinner on focus ## 4.0.3 diff --git a/Fluent.Ribbon.Showcase/TestContent.xaml b/Fluent.Ribbon.Showcase/TestContent.xaml index 0254d24c7..ca477f39d 100644 --- a/Fluent.Ribbon.Showcase/TestContent.xaml +++ b/Fluent.Ribbon.Showcase/TestContent.xaml @@ -2187,7 +2187,8 @@ InputWidth="75" Format="0 px" Header="Right:" - Icon="pack://application:,,,/Fluent;component/Themes/Images/Warning.png" /> + Icon="pack://application:,,,/Fluent;component/Themes/Images/Warning.png" + SelectAllTextOnFocus="True" /> ((double)e.OldValue, (double)e.NewValue)); - } + spinner.ValueChanged?.Invoke(spinner, new RoutedPropertyChangedEventArgs((double)e.OldValue, (double)e.NewValue)); } private void ValueToTextBoxText() { - if (this.IsTemplateValid()) + if (this.textBox == null) { - var newText = (string)this.TextToValueConverter.ConvertBack(this.Value, typeof(string), this.Format, CultureInfo.CurrentCulture); - this.textBox.Text = newText; - this.Text = newText; + return; } + + var newText = (string)this.TextToValueConverter.ConvertBack(this.Value, typeof(string), this.Format, CultureInfo.CurrentCulture); + this.textBox.Text = newText; + this.Text = newText; } #endregion @@ -327,6 +326,21 @@ public IValueConverter TextToValueConverter #endregion TextToValueConverter + /// + /// Defines wether all text should be select as soon as this control gets focus. + /// + public bool SelectAllTextOnFocus + { + get { return (bool)this.GetValue(SelectAllTextOnFocusProperty); } + set { this.SetValue(SelectAllTextOnFocusProperty, value); } + } + + /// + /// for + /// + public static readonly DependencyProperty SelectAllTextOnFocusProperty = + DependencyProperty.Register("SelectAllTextOnFocus", typeof(bool), typeof(Spinner), new PropertyMetadata(false)); + #endregion #region Constructors @@ -355,12 +369,22 @@ static Spinner() /// public override void OnApplyTemplate() { - if (this.IsTemplateValid()) + if (this.buttonUp != null) { this.buttonUp.Click -= this.OnButtonUpClick; + BindingOperations.ClearAllBindings(this.buttonUp); + } + + if (this.buttonDown != null) + { this.buttonDown.Click -= this.OnButtonDownClick; BindingOperations.ClearAllBindings(this.buttonDown); - BindingOperations.ClearAllBindings(this.buttonUp); + } + + if (this.textBox != null) + { + this.textBox.LostKeyboardFocus -= this.OnTextBoxLostKeyboardFocus; + this.textBox.PreviewKeyDown -= this.OnTextBoxPreviewKeyDown; } // Get template childs @@ -381,10 +405,10 @@ public override void OnApplyTemplate() Bind(this, this.buttonUp, "Interval", RepeatButton.IntervalProperty, BindingMode.OneWay); Bind(this, this.buttonDown, "Interval", RepeatButton.IntervalProperty, BindingMode.OneWay); - // Events subscribing this.buttonUp.Click += this.OnButtonUpClick; this.buttonDown.Click += this.OnButtonDownClick; + this.textBox.GotFocus += this.HandleTextBoxGotFocus; this.textBox.LostKeyboardFocus += this.OnTextBoxLostKeyboardFocus; this.textBox.PreviewKeyDown += this.OnTextBoxPreviewKeyDown; @@ -407,24 +431,36 @@ private bool IsTemplateValid() /// public override void OnKeyTipPressed() { - if (this.IsTemplateValid() == false) + if (this.textBox == null) { return; } // Use dispatcher to avoid focus moving to backup'ed element // (focused element before keytips processing) - this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, + this.Dispatcher.BeginInvoke(DispatcherPriority.Background, (ThreadStart)(() => { this.textBox.SelectAll(); this.textBox.Focus(); })); - base.OnKeyTipPressed(); + } + + private void HandleTextBoxGotFocus(object sender, RoutedEventArgs e) + { + if (this.SelectAllTextOnFocus) + { + // Async because setting the carret happens after focus. + this.Dispatcher.BeginInvoke(DispatcherPriority.Background, + (ThreadStart)(() => + { + this.textBox.SelectAll(); + })); + } } /// - /// Invoked when an unhandled System.Windows.Input.Keyboard.KeyUp�attached event reaches + /// Invoked when an unhandled System.Windows.Input.Keyboard.KeyUp attached event reaches /// an element in its route that is derived from this class. Implement this method to add class handling for this event. /// /// The System.Windows.Input.KeyEventArgs that contains the event data.