123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- using System;
- using System.ComponentModel;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Media;
- namespace Microsoft.Windows.Shell;
- [DefaultEvent("Click")]
- public sealed class ThumbButtonInfo : Freezable, ICommandSource
- {
- protected override Freezable CreateInstanceCore()
- {
- return new ThumbButtonInfo();
- }
- public Visibility Visibility
- {
- get
- {
- return (Visibility) base.GetValue(ThumbButtonInfo.VisibilityProperty);
- }
- set
- {
- base.SetValue(ThumbButtonInfo.VisibilityProperty, value);
- }
- }
- public bool DismissWhenClicked
- {
- get
- {
- return (bool) base.GetValue(ThumbButtonInfo.DismissWhenClickedProperty);
- }
- set
- {
- base.SetValue(ThumbButtonInfo.DismissWhenClickedProperty, value);
- }
- }
- public ImageSource ImageSource
- {
- get
- {
- return (ImageSource) base.GetValue(ThumbButtonInfo.ImageSourceProperty);
- }
- set
- {
- base.SetValue(ThumbButtonInfo.ImageSourceProperty, value);
- }
- }
- public bool IsBackgroundVisible
- {
- get
- {
- return (bool) base.GetValue(ThumbButtonInfo.IsBackgroundVisibleProperty);
- }
- set
- {
- base.SetValue(ThumbButtonInfo.IsBackgroundVisibleProperty, value);
- }
- }
- public string Description
- {
- get
- {
- return (string) base.GetValue(ThumbButtonInfo.DescriptionProperty);
- }
- set
- {
- base.SetValue(ThumbButtonInfo.DescriptionProperty, value);
- }
- }
- private static object _CoerceDescription(DependencyObject d, object value)
- {
- string text = (string) value;
- if (text != null && text.Length >= 260)
- {
- text = text.Substring(0, 259);
- }
- return text;
- }
- private object _CoerceIsEnabledValue(object value)
- {
- bool flag = (bool) value;
- return flag && this._CanExecute;
- }
- public bool IsEnabled
- {
- get
- {
- return (bool) base.GetValue(ThumbButtonInfo.IsEnabledProperty);
- }
- set
- {
- base.SetValue(ThumbButtonInfo.IsEnabledProperty, value);
- }
- }
- public bool IsInteractive
- {
- get
- {
- return (bool) base.GetValue(ThumbButtonInfo.IsInteractiveProperty);
- }
- set
- {
- base.SetValue(ThumbButtonInfo.IsInteractiveProperty, value);
- }
- }
- private void _OnCommandChanged(DependencyPropertyChangedEventArgs e)
- {
- ICommand command = (ICommand) e.OldValue;
- ICommand command2 = (ICommand) e.NewValue;
- if (command == command2)
- {
- return;
- }
- if (command != null)
- {
- this._UnhookCommand(command);
- }
- if (command2 != null)
- {
- this._HookCommand(command2);
- }
- }
- private bool _CanExecute
- {
- get
- {
- return (bool) base.GetValue(ThumbButtonInfo._CanExecuteProperty);
- }
- set
- {
- base.SetValue(ThumbButtonInfo._CanExecuteProperty, value);
- }
- }
- public event EventHandler Click;
- internal void InvokeClick()
- {
- EventHandler click = this.Click;
- if (click != null)
- {
- click(this, EventArgs.Empty);
- }
- this._InvokeCommand();
- }
- private void _InvokeCommand()
- {
- ICommand command = this.Command;
- if (command != null)
- {
- object commandParameter = this.CommandParameter;
- IInputElement commandTarget = this.CommandTarget;
- RoutedCommand routedCommand = command as RoutedCommand;
- if (routedCommand != null)
- {
- if (routedCommand.CanExecute(commandParameter, commandTarget))
- {
- routedCommand.Execute(commandParameter, commandTarget);
- return;
- }
- }
- else if (command.CanExecute(commandParameter))
- {
- command.Execute(commandParameter);
- }
- }
- }
- private void _UnhookCommand(ICommand command)
- {
- command.CanExecuteChanged -= this._commandEvent;
- this._commandEvent = null;
- this._UpdateCanExecute();
- }
- private void _HookCommand(ICommand command)
- {
- this._commandEvent = delegate (object sender, EventArgs e)
- {
- this._UpdateCanExecute();
- };
- command.CanExecuteChanged += this._commandEvent;
- this._UpdateCanExecute();
- }
- private void _UpdateCanExecute()
- {
- if (this.Command == null)
- {
- this._CanExecute = true;
- return;
- }
- object commandParameter = this.CommandParameter;
- IInputElement commandTarget = this.CommandTarget;
- RoutedCommand routedCommand = this.Command as RoutedCommand;
- if (routedCommand != null)
- {
- this._CanExecute = routedCommand.CanExecute(commandParameter, commandTarget);
- return;
- }
- this._CanExecute = this.Command.CanExecute(commandParameter);
- }
- public ICommand Command
- {
- get
- {
- return (ICommand) base.GetValue(ThumbButtonInfo.CommandProperty);
- }
- set
- {
- base.SetValue(ThumbButtonInfo.CommandProperty, value);
- }
- }
- public object CommandParameter
- {
- get
- {
- return base.GetValue(ThumbButtonInfo.CommandParameterProperty);
- }
- set
- {
- base.SetValue(ThumbButtonInfo.CommandParameterProperty, value);
- }
- }
- public IInputElement CommandTarget
- {
- get
- {
- return (IInputElement) base.GetValue(ThumbButtonInfo.CommandTargetProperty);
- }
- set
- {
- base.SetValue(ThumbButtonInfo.CommandTargetProperty, value);
- }
- }
- private EventHandler _commandEvent;
- public static readonly DependencyProperty VisibilityProperty = DependencyProperty.Register("Visibility", typeof(Visibility), typeof(ThumbButtonInfo), new PropertyMetadata(Visibility.Visible));
- public static readonly DependencyProperty DismissWhenClickedProperty = DependencyProperty.Register("DismissWhenClicked", typeof(bool), typeof(ThumbButtonInfo), new PropertyMetadata(false));
- public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(ThumbButtonInfo), new PropertyMetadata(null));
- public static readonly DependencyProperty IsBackgroundVisibleProperty = DependencyProperty.Register("IsBackgroundVisible", typeof(bool), typeof(ThumbButtonInfo), new PropertyMetadata(true));
- public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register("Description", typeof(string), typeof(ThumbButtonInfo), new PropertyMetadata(string.Empty, null, new CoerceValueCallback(ThumbButtonInfo._CoerceDescription)));
- public static readonly DependencyProperty IsEnabledProperty = DependencyProperty.Register("IsEnabled", typeof(bool), typeof(ThumbButtonInfo), new PropertyMetadata(true, null, (DependencyObject d, object e) => ((ThumbButtonInfo) d)._CoerceIsEnabledValue(e)));
- public static readonly DependencyProperty IsInteractiveProperty = DependencyProperty.Register("IsInteractive", typeof(bool), typeof(ThumbButtonInfo), new PropertyMetadata(true));
- public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(ThumbButtonInfo), new PropertyMetadata(null, delegate (DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((ThumbButtonInfo) d)._OnCommandChanged(e);
- }));
- public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register("CommandParameter", typeof(object), typeof(ThumbButtonInfo), new PropertyMetadata(null, delegate (DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((ThumbButtonInfo) d)._UpdateCanExecute();
- }));
- public static readonly DependencyProperty CommandTargetProperty = DependencyProperty.Register("CommandTarget", typeof(IInputElement), typeof(ThumbButtonInfo), new PropertyMetadata(null, delegate (DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((ThumbButtonInfo) d)._UpdateCanExecute();
- }));
- private static readonly DependencyProperty _CanExecuteProperty = DependencyProperty.Register("_CanExecute", typeof(bool), typeof(ThumbButtonInfo), new PropertyMetadata(true, delegate (DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- d.CoerceValue(ThumbButtonInfo.IsEnabledProperty);
- }));
- }
|