Here are the examples of the csharp api System.Windows.Input.ICommand.Execute(object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
833 Examples
19
Source : HorizontalList.cs
with MIT License
from Azure-Samples
with MIT License
from Azure-Samples
private static void OnSelectedItemChanged(BindableObject bindable, object oldValue, object newValue)
{
var itemsView = (HorizontalList)bindable;
if (newValue == oldValue && newValue != null)
{
return;
}
itemsView.SelectedItemChanged?.Invoke(itemsView, EventArgs.Empty);
if (itemsView.SelectedCommand?.CanExecute(newValue) ?? false)
{
itemsView.SelectedCommand?.Execute(newValue);
}
}
19
Source : HyperLink.axaml.cs
with MIT License
from b-editor
with MIT License
from b-editor
private void Text_PointerReleased(object? sender, PointerReleasedEventArgs e)
{
if (_pressed)
{
Command?.Execute(null);
_pressed = false;
}
}
19
Source : MenuBind.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
private static ICommand WrapCommand(ICommand command, IMenuCommandItem cmd)
{
if (!cmd.Shortcut.HasValue || !Enum.TryParse(cmd.Shortcut.Value.Key, out Key key))
return command;
// ok, so this is terrible, but TextBox gestures handling is inside OnKeyDown
// which is executed AFTER handling application wise shortcuts
// However application wise shortcuts take higher priority
// and effectively TextBox doesn't handle copy/paste/cut/undo/redo -.-
var original = command;
command = OverrideCommand<ICustomCopyPaste>(command, Key.C, key, cmd, tb => tb.DoCopy((IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard))));
command = OverrideCommand<ICustomCopyPaste>(command, Key.V, key, cmd, tb => tb.DoPaste().ListenErrors());
command = OverrideCommand<TextBox>(command, Key.C, key, cmd, tb => tb.Copy());
command = OverrideCommand<TextBox>(command, Key.X, key, cmd, tb => tb.Cut());
command = OverrideCommand<TextBox>(command, Key.V, key, cmd, tb => tb.Paste());
command = OverrideCommand<TextBox>(command, Key.Z, key, cmd, Undo);
command = OverrideCommand<TextBox>(command, Key.Y, key, cmd, Redo);
command = OverrideCommand<FixedTextBox>(command, Key.V, key, cmd, tb => tb.CustomPaste());
command = OverrideCommand<TextArea>(command, Key.Z, key, cmd, tb =>
{
var te = GetTextEditor(tb);
if (te == null || te.Doreplacedent.UndoStack.SizeLimit == 0)
return false;
te.Undo();
return true;
});
command = OverrideCommand<TextArea>(command, Key.Y, key, cmd, tb =>
{
var te = GetTextEditor(tb);
if (te == null || te.Doreplacedent.UndoStack.SizeLimit == 0)
return false;
te.Redo();
return true;
});
command = OverrideCommand<TextArea>(command, Key.C, key, cmd, tb => ApplicationCommands.Copy.Execute(null, tb));
command = OverrideCommand<TextArea>(command, Key.X, key, cmd, tb => ApplicationCommands.Cut.Execute(null, tb));
command = OverrideCommand<TextArea>(command, Key.V, key, cmd, tb => ApplicationCommands.Paste.Execute(null, tb));
var newCommand = new DelegateCommand(() => command.Execute(null), () => command.CanExecute(null));
original.CanExecuteChanged += (_, _) => newCommand.RaiseCanExecuteChanged();
return newCommand;
}
19
Source : MenuBind.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
private static ICommand OverrideCommand<T>(ICommand command, Key require, Key commandKey, IMenuCommandItem item, Func<T, bool> func)
{
if (require != commandKey || !(item.Shortcut?.Control ?? false))
return command;
return new DelegateCommand(() =>
{
bool executed = false;
if (FocusManager.Instance.Current is T t)
executed = func(t);
if (!executed && command.CanExecute(null))
command.Execute(null);
}, () =>
{
if (FocusManager.Instance.Current is T t)
return true;
return command.CanExecute(null);
});
}
19
Source : MenuBind.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
private static ICommand OverrideCommand<T>(ICommand command, Key require, Key commandKey, IMenuCommandItem item, Action<T> func)
{
if (require != commandKey || !(item.Shortcut?.Control ?? false))
return command;
return new DelegateCommand(() =>
{
if (FocusManager.Instance.Current is T t)
func(t);
else if (command.CanExecute(null))
command.Execute(null);
}, () =>
{
if (FocusManager.Instance.Current is T t)
return true;
return command.CanExecute(null);
});
}
19
Source : ViewItemDoubleClickCommand.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
private static void OnDoubleClick(object sender, MouseButtonEventArgs e)
{
var d = sender as DependencyObject;
if (d == null)
return;
var command = GetCommand(d);
if (command == null)
return;
var parameter = GetCommandParameter(d);
if (!command.CanExecute(parameter))
return;
command.Execute(parameter);
}
19
Source : BetterKeyBinding.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
public void Execute(object? parameter)
{
if (FocusManager.Instance.Current is TextBox tb)
{
var ev = new KeyEventArgs()
{
Key = Gesture.Key,
KeyModifiers = Gesture.KeyModifiers,
RoutedEvent = InputElement.KeyDownEvent
};
tb.RaiseEvent(ev);
if (!ev.Handled)
CustomCommand.Execute(parameter);
}
else
CustomCommand.Execute(parameter);
}
19
Source : SmartActionView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void DeselectOthers()
{
DeselectAllButActionsRequest?.Execute(null);
}
19
Source : SmartConditionView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void OnDirectEdit(object context)
{
DirectEditParameter?.Execute(context);
}
19
Source : SmartConditionView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void DeselectOthers()
{
DeselectAllButConditionsRequest?.Execute(null);
}
19
Source : SmartEventView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void OnEdit()
{
EditEventCommand?.Execute(DataContext);
}
19
Source : SmartEventView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void DeselectOthers()
{
DeselectActionsOfDeselectedEventsRequest?.Execute(null);
}
19
Source : GlobalVaraiableView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);
if (e.ClickCount == 1)
{
DeselectAllButGlobalVariablesRequest?.Execute(null);
if (!IsSelected)
{
if (!Keyboard.IsKeyDown(Key.LeftCtrl))
DeselectAllRequest?.Execute(null);
IsSelected = true;
}
}
else if (e.ClickCount == 2)
EditGlobalVariableCommand?.Execute(DataContext);
}
19
Source : SmartActionView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);
if (e.ClickCount == 1)
{
if (DirectEditParameter != null)
{
if (e.OriginalSource is Run originalRun && originalRun.DataContext != null &&
originalRun.DataContext != DataContext)
{
DirectEditParameter.Execute(originalRun.DataContext);
return;
}
}
DeselectAllButActionsRequest?.Execute(null);
if (!IsSelected)
{
if (!Keyboard.IsKeyDown(Key.LeftCtrl))
DeselectAllRequest?.Execute(null);
IsSelected = true;
}
}
else if (e.ClickCount == 2)
EditActionCommand?.Execute(DataContext);
}
19
Source : SmartActionView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);
if (e.ClickCount == 1)
{
if (DirectEditParameter != null)
{
if (e.OriginalSource is Run originalRun && originalRun.DataContext != null &&
originalRun.DataContext != DataContext)
{
DirectEditParameter.Execute(originalRun.DataContext);
return;
}
}
DeselectAllButActionsRequest?.Execute(null);
if (!IsSelected)
{
if (!Keyboard.IsKeyDown(Key.LeftCtrl))
DeselectAllRequest?.Execute(null);
IsSelected = true;
}
}
else if (e.ClickCount == 2)
EditActionCommand?.Execute(DataContext);
}
19
Source : SmartConditionView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);
if (e.ClickCount == 1)
{
if (DirectEditParameter != null)
{
if (e.OriginalSource is Run originalRun && originalRun.DataContext != null &&
originalRun.DataContext != DataContext)
{
DirectEditParameter.Execute(originalRun.DataContext);
return;
}
}
DeselectAllButConditionsRequest?.Execute(null);
if (!IsSelected)
{
if (!Keyboard.IsKeyDown(Key.LeftCtrl))
DeselectAllRequest?.Execute(null);
IsSelected = true;
}
}
else if (e.ClickCount == 2)
EditConditionCommand?.Execute(DataContext);
}
19
Source : SmartEventView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{
if (e.ClickCount == 1)
{
if (DirectEditParameter != null)
{
if (e.OriginalSource is Run originalRun && originalRun.DataContext != null &&
originalRun.DataContext != DataContext)
{
DirectEditParameter.Execute(originalRun.DataContext);
return;
}
}
DeselectActionsOfDeselectedEventsRequest?.Execute(null);
if (!IsSelected)
{
if (!Keyboard.IsKeyDown(Key.LeftCtrl))
DeselectAllRequest?.Execute(null);
IsSelected = true;
}
e.Handled = true;
}
else if (e.ClickCount == 2)
{
EditEventCommand?.Execute(DataContext);
e.Handled = true;
}
base.OnPreviewMouseDown(e);
}
19
Source : SmartEventView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{
if (e.ClickCount == 1)
{
if (DirectEditParameter != null)
{
if (e.OriginalSource is Run originalRun && originalRun.DataContext != null &&
originalRun.DataContext != DataContext)
{
DirectEditParameter.Execute(originalRun.DataContext);
return;
}
}
DeselectActionsOfDeselectedEventsRequest?.Execute(null);
if (!IsSelected)
{
if (!Keyboard.IsKeyDown(Key.LeftCtrl))
DeselectAllRequest?.Execute(null);
IsSelected = true;
}
e.Handled = true;
}
else if (e.ClickCount == 2)
{
EditEventCommand?.Execute(DataContext);
e.Handled = true;
}
base.OnPreviewMouseDown(e);
}
19
Source : SmartScriptPanelLayout.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
private void StopDragging()
{
ReleaseMouseCapture();
if (draggingEvents)
DropItems?.Execute(OverIndexEvent);
else if (draggingActions)
{
DropActions?.Execute(new DropActionsConditionsArgs
{EventIndex = overIndexAction.eventIndex, ActionIndex = overIndexAction.actionIndex});
}
else if (draggingConditions)
{
DropConditions?.Execute(new DropActionsConditionsArgs
{EventIndex = overIndexCondition.eventIndex, ActionIndex = overIndexCondition.conditionIndex});
}
draggingEvents = false;
draggingActions = false;
draggingConditions = false;
InvalidateArrange();
InvalidateVisual();
}
19
Source : SmartScriptPanelLayout.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
private void StopDragging()
{
ReleaseMouseCapture();
if (draggingEvents)
DropItems?.Execute(OverIndexEvent);
else if (draggingActions)
{
DropActions?.Execute(new DropActionsConditionsArgs
{EventIndex = overIndexAction.eventIndex, ActionIndex = overIndexAction.actionIndex});
}
else if (draggingConditions)
{
DropConditions?.Execute(new DropActionsConditionsArgs
{EventIndex = overIndexCondition.eventIndex, ActionIndex = overIndexCondition.conditionIndex});
}
draggingEvents = false;
draggingActions = false;
draggingConditions = false;
InvalidateArrange();
InvalidateVisual();
}
19
Source : SmartScriptView.xaml.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
private void UIElement_OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Delete)
DeleteEventCommand?.Execute(this);
}
19
Source : GlobalVariableView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void DeselectOthers()
{
DeselectAllButGlobalVariablesRequest?.Execute(null);
}
19
Source : GlobalVariableView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void OnEdit()
{
EditGlobalVariableCommand?.Execute(DataContext);
}
19
Source : SelectableTemplatedControl.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
base.OnPointerPressed(e);
lastPressedTimestamp = e.Timestamp;
lastClickCount = e.ClickCount;
lastPressedWithControlOn = IsMultiSelect(e.KeyModifiers);
pressPosition = e.GetPosition(this);
if (e.ClickCount == 1)
{
if (e.Source is FormattedTextBlock tb && tb.OverContext != null)
return;
if (!lastPressedWithControlOn)
DeselectAllRequest?.Execute(null);
else if (!IsSelected)
DeselectOthers();
if (!lastPressedWithControlOn && !IsSelected)
IsSelected = true;
e.Handled = true;
}
}
19
Source : SmartConditionView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void OnEdit()
{
EditConditionCommand?.Execute(DataContext);
}
19
Source : SmartScriptPanelLayout.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
private void StopDragging()
{
if (AnythingSelected())
{
if (draggingEvents)
DropItems?.Execute(new DropActionsConditionsArgs{EventIndex = OverIndexEvent.eventIndex, ActionIndex = 0, Copy = isCopying});
else if (draggingActions)
{
DropActions?.Execute(new DropActionsConditionsArgs
{EventIndex = overIndexAction.eventIndex, ActionIndex = overIndexAction.actionIndex, Copy = isCopying});
}
else if (draggingConditions)
{
DropConditions?.Execute(new DropActionsConditionsArgs
{EventIndex = overIndexCondition.eventIndex, ActionIndex = overIndexCondition.conditionIndex, Copy = isCopying});
}
}
draggingEvents = false;
draggingActions = false;
draggingConditions = false;
InvalidateArrange();
InvalidateVisual();
}
19
Source : SmartConditionView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);
if (e.ClickCount == 1)
{
if (DirectEditParameter != null)
{
if (e.OriginalSource is Run originalRun && originalRun.DataContext != null &&
originalRun.DataContext != DataContext)
{
DirectEditParameter.Execute(originalRun.DataContext);
return;
}
}
DeselectAllButConditionsRequest?.Execute(null);
if (!IsSelected)
{
if (!Keyboard.IsKeyDown(Key.LeftCtrl))
DeselectAllRequest?.Execute(null);
IsSelected = true;
}
}
else if (e.ClickCount == 2)
EditConditionCommand?.Execute(DataContext);
}
19
Source : SmartActionView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void OnEdit()
{
EditActionCommand?.Execute(DataContext);
}
19
Source : GlobalVaraiableView.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);
if (e.ClickCount == 1)
{
DeselectAllButGlobalVariablesRequest?.Execute(null);
if (!IsSelected)
{
if (!Keyboard.IsKeyDown(Key.LeftCtrl))
DeselectAllRequest?.Execute(null);
IsSelected = true;
}
}
else if (e.ClickCount == 2)
EditGlobalVariableCommand?.Execute(DataContext);
}
19
Source : MainWindow.xaml.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
private void DockingManager_OnDoreplacedentClosed(object sender, DoreplacedentClosedEventArgs e)
{
DoreplacedentClosedCommand?.Execute(e.Doreplacedent.Content);
}
19
Source : AsyncAutoCommand.cs
with The Unlicense
from BAndysc
with The Unlicense
from BAndysc
public void Execute(object? parameter)
{
((ICommand) command).Execute(parameter);
}
19
Source : DropDownButton.cs
with MIT License
from barry-jones
with MIT License
from barry-jones
protected override void OnClick()
{
if(DropDownContextMenu == null) return;
if(DropDownButtonCommand != null) DropDownButtonCommand.Execute(null);
// If there is a drop-down replacedigned to this button, then position and display it
DropDownContextMenu.PlacementTarget = this;
DropDownContextMenu.Placement = PlacementMode.Bottom;
DropDownContextMenu.IsOpen = !DropDownContextMenu.IsOpen;
}
19
Source : MainWindow.xaml.cs
with MIT License
from barry-jones
with MIT License
from barry-jones
private void mainWindow_PreviewKeyDown(object sender, KeyEventArgs e)
{
// make sure that all our input bindings are taken care of, this fixes
// an issue where the ctrl+f binding is ignored in some parts of the app.
foreach(InputBinding inputBinding in this.InputBindings)
{
KeyGesture keyGesture = inputBinding.Gesture as KeyGesture;
if(keyGesture != null && keyGesture.Key == e.Key && keyGesture.Modifiers == e.KeyboardDevice.Modifiers)
{
if(inputBinding.Command != null)
{
inputBinding.Command.Execute(0);
e.Handled = true;
}
}
}
}
19
Source : LottieExtensions.cs
with Apache License 2.0
from Baseflow
with Apache License 2.0
from Baseflow
public static void ExecuteCommandIfPossible(this ICommand command, object parameter = null)
{
if (command?.CanExecute(parameter) == true)
{
command.Execute(parameter);
}
}
19
Source : MenuDialogLabel.cs
with MIT License
from Baseflow
with MIT License
from Baseflow
private void MenuDialogLabel_SizeChanged(object sender, EventArgs e)
{
SizeChangeCommand?.Execute(new Dictionary<string, object>
{
{"width", Width },
{"parameter", Convert.ToInt32(GetValue(MaterialMenuDialog.ParameterProperty)) }
});
SizeChanged -= MenuDialogLabel_SizeChanged;
}
19
Source : MaterialCard.cs
with MIT License
from Baseflow
with MIT License
from Baseflow
protected virtual void OnClick()
{
Clicked?.Invoke(this, EventArgs.Empty);
ClickCommand?.Execute(ClickCommandParameter);
}
19
Source : MaterialIconButton.xaml.cs
with MIT License
from Baseflow
with MIT License
from Baseflow
protected virtual void OnButtonClicked(bool handled)
{
Clicked?.Invoke(this, EventArgs.Empty);
InternalCommand?.Execute(null);
if (handled && Command?.CanExecute(CommandParameter) == true)
{
Command.Execute(CommandParameter);
}
}
19
Source : LinkerPleaseInclude.cs
with MIT License
from Baseflow
with MIT License
from Baseflow
public void Include(ICommand command)
{
command.CanExecuteChanged += (s, e) => { if (command.CanExecute(null)) command.Execute(null); };
}
19
Source : ToggleSwitch.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from beckzhu
private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var toggleSwitch = (ToggleSwitch)d;
if (toggleSwitch._toggleButton != null)
{
var oldValue = (bool?)e.OldValue;
var newValue = (bool?)e.NewValue;
if (oldValue != newValue)
{
var command = toggleSwitch.CheckChangedCommand;
var commandParameter = toggleSwitch.CheckChangedCommandParameter ?? toggleSwitch;
if (command != null && command.CanExecute(commandParameter))
{
command.Execute(commandParameter);
}
var eh = toggleSwitch.IsCheckedChanged;
if (eh != null)
{
eh(toggleSwitch, EventArgs.Empty);
}
}
}
}
19
Source : CommandTriggerAction.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from beckzhu
protected override void Invoke(object parameter)
{
if (this.replacedociatedObject == null || (this.replacedociatedObject != null && !this.replacedociatedObject.IsEnabled))
{
return;
}
var command = this.Command;
if (command != null)
{
var commandParameter = this.GetCommandParameter();
if (command.CanExecute(commandParameter))
{
command.Execute(commandParameter);
}
}
}
19
Source : TextBoxHelper.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from beckzhu
public static void ButtonClicked(object sender, RoutedEventArgs e)
{
var button = (Button)sender;
var parent = button.GetAncestors().FirstOrDefault(a => a is TextBox || a is PreplacedwordBox || a is ComboBox);
var command = GetButtonCommand(parent);
var commandParameter = GetButtonCommandParameter(parent) ?? parent;
if (command != null && command.CanExecute(commandParameter))
{
command.Execute(commandParameter);
}
if (GetClearTextButton(parent))
{
if (parent is TextBox)
{
((TextBox)parent).Clear();
((TextBox)parent).GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
}
else if (parent is PreplacedwordBox)
{
((PreplacedwordBox)parent).Clear();
((PreplacedwordBox)parent).GetBindingExpression(PreplacedwordBoxBindingBehavior.PreplacedwordProperty)?.UpdateSource();
}
else if (parent is ComboBox)
{
if (((ComboBox)parent).IsEditable)
{
((ComboBox)parent).Text = string.Empty;
((ComboBox)parent).GetBindingExpression(ComboBox.TextProperty)?.UpdateSource();
}
((ComboBox)parent).SelectedItem = null;
((ComboBox)parent).GetBindingExpression(ComboBox.SelectedItemProperty)?.UpdateSource();
}
}
}
19
Source : HamburgerMenu.Options.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from beckzhu
public void RaiseOptionsItemCommand()
{
var command = OptionsItemCommand;
var commandParameter = OptionsItemCommandParameter ?? this;
if (command != null && command.CanExecute(commandParameter))
{
command.Execute(commandParameter);
}
}
19
Source : HamburgerMenu.Properties.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from beckzhu
public void RaiseItemCommand()
{
var command = ItemCommand;
var commandParameter = ItemCommandParameter ?? this;
if (command != null && command.CanExecute(commandParameter))
{
command.Execute(commandParameter);
}
}
19
Source : Flyout.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from beckzhu
private void InternalCloseCommandExecuteAction(object o)
{
var closeCommand = this.CloseCommand;
// close the Flyout only if there is no command
if (closeCommand == null)
{
this.SetCurrentValue(IsOpenProperty, false);
}
else
{
var closeCommandParameter = this.CloseCommandParameter ?? this;
if (closeCommand.CanExecute(closeCommandParameter))
{
// force the command handler to run
closeCommand.Execute(closeCommandParameter);
}
}
}
19
Source : CommandHelpers.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from beckzhu
[SecurityCritical]
internal static void CriticalExecuteCommandSource(ICommandSource commandSource)
{
var command = commandSource.Command;
if (command == null)
{
return;
}
var commandParameter = commandSource.CommandParameter ?? commandSource;
var routedCommand = command as RoutedCommand;
if (routedCommand != null)
{
var target = commandSource.CommandTarget ?? commandSource as IInputElement;
if (routedCommand.CanExecute(commandParameter, target))
{
routedCommand.Execute(commandParameter, target);
}
}
else
{
if (command.CanExecute(commandParameter))
{
command.Execute(commandParameter);
}
}
}
19
Source : MetroTabControl.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from beckzhu
internal void CloseThisTabItem( MetroTabItem tabItem)
{
if (tabItem == null)
{
throw new ArgumentNullException(nameof(tabItem));
}
if (this.CloseTabCommand != null)
{
var closeTabCommandParameter = tabItem.CloseTabCommandParameter ?? tabItem;
if (this.CloseTabCommand.CanExecute(closeTabCommandParameter))
{
this.CloseTabCommand.Execute(closeTabCommandParameter);
}
}
else
{
// KIDS: don't try this at home
// this is not good MVVM habits and I'm only doing it
// because I want the demos to be absolutely replaceding
// the control is allowed to cancel this event
if (this.RaiseTabItemClosingEvent(tabItem))
{
return;
}
if (this.ItemsSource == null)
{
// if the list is hard-coded (i.e. has no ItemsSource)
// then we remove the item from the collection
tabItem.ClearStyle();
this.Items.Remove(tabItem);
}
else
{
// if ItemsSource is something we cannot work with, bail out
var collection = this.ItemsSource as IList;
if (collection == null)
{
return;
}
// find the item and kill it (I mean, remove it)
var item2Remove = collection.OfType<object>().FirstOrDefault(item => tabItem == item || tabItem.DataContext == item);
if (item2Remove != null)
{
tabItem.ClearStyle();
collection.Remove(item2Remove);
}
}
}
}
19
Source : ToggleSwitch.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from beckzhu
private void CheckedHandler(object sender, RoutedEventArgs e)
{
var command = this.CheckedCommand;
var commandParameter = this.CheckedCommandParameter ?? this;
if (command != null && command.CanExecute(commandParameter))
{
command.Execute(commandParameter);
}
SafeRaise.Raise(Checked, this, e);
}
19
Source : ToggleSwitch.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from beckzhu
private void UncheckedHandler(object sender, RoutedEventArgs e)
{
var command = this.UnCheckedCommand;
var commandParameter = this.UnCheckedCommandParameter ?? this;
if (command != null && command.CanExecute(commandParameter))
{
command.Execute(commandParameter);
}
SafeRaise.Raise(Unchecked, this, e);
}
19
Source : GridViewSortExtension.cs
with MIT License
from benruehl
with MIT License
from benruehl
private static void ColumnHeader_Click(object sender, RoutedEventArgs e)
{
GridViewColumnHeader headerClicked = e.OriginalSource as GridViewColumnHeader;
if (headerClicked?.Column != null)
{
string propertyName = GetPropertyName(headerClicked.Column);
if (string.IsNullOrEmpty(propertyName))
{
// use DisplayMemberBinding if no property name has been specified
propertyName = (headerClicked.Column?.DisplayMemberBinding as Binding)?.Path?.Path;
}
if (!string.IsNullOrEmpty(propertyName))
{
ListView listView = GetAncestor<ListView>(headerClicked);
if (listView != null)
{
ICommand command = GetCommand(listView);
if (command != null)
{
if (command.CanExecute(propertyName))
{
command.Execute(propertyName);
}
}
else if (GetAutoSort(listView))
{
ApplySort(listView.Items, propertyName, listView, headerClicked);
}
}
}
}
}
19
Source : FastGridView.cs
with MIT License
from Binwell
with MIT License
from Binwell
public void Refresh()
{
if (IsPullToRefreshEnabled == false) return;
RefreshCommand?.Execute(null);
}
See More Examples