123456789101112131415161718192021222324252627282930313233 |
- using System.Windows;
- namespace WpfControlLibrary.IpAddress
- {
- public static class FocusChangeExtension
- {
- public static bool GetIsFocused(DependencyObject obj)
- {
- return ( bool ) obj.GetValue(IsFocusedProperty);
- }
- public static void SetIsFocused(DependencyObject obj, bool value)
- {
- obj.SetValue(IsFocusedProperty, value);
- }
- public static readonly DependencyProperty IsFocusedProperty =
- DependencyProperty.RegisterAttached(
- "IsFocused", typeof(bool), typeof(FocusChangeExtension),
- new UIPropertyMetadata(false, OnIsFocusedPropertyChanged));
- private static void OnIsFocusedPropertyChanged(
- DependencyObject d,
- DependencyPropertyChangedEventArgs e)
- {
- var control = (UIElement)d;
- if ( ( bool ) e.NewValue )
- {
- control.Focus();
- }
- }
- }
- }
|