System.Windows.Input.ICommand.CanExecute(object)

Here are the examples of the csharp api System.Windows.Input.ICommand.CanExecute(object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

518 Examples 7

19 Source : SegmentedControl.cs
with MIT License
from 1iveowl

[EditorBrowsable(EditorBrowsableState.Never)]
        public void RaiseSelectionChanged()
        {
            OnSegmentSelected?.Invoke(this, new SegmentSelectEventArgs { NewValue = this.SelectedSegment });

            if (!(SegmentSelectedCommand is null) && SegmentSelectedCommand.CanExecute(SegmentSelectedCommandParameter))
            {
                SegmentSelectedCommand.Execute(SegmentSelectedCommandParameter);
            }
        }

19 Source : InvokeCommandAction.cs
with MIT License
from 1iveowl

public async Task<bool> Execute(object sender, object parameter)
        {
            if (Command is null)
            {
                return false;
            }
            
            object resolvedParameter;

            if (!(CommandParameter is null))
            {
                resolvedParameter = CommandParameter;
            }
            else if (!(Converter is null))
            {
                resolvedParameter = Converter.Convert(parameter, typeof(object), ConverterParameter, null);
            }
            else
            {
                resolvedParameter = parameter;
            }

            if (!Command.CanExecute(resolvedParameter))
            {
                return false;
            }

            Command.Execute(resolvedParameter);

            await Task.CompletedTask;

            return true;
        }

19 Source : DigitalAnalyzerScrollBehavior.cs
with MIT License
from ABTSoftware

private void ScrollViewer_OnPreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
            {
                if (ChangeChannelHeightCommand?.CanExecute(null) != true) return;
                ChangeChannelHeightCommand.Execute(e.Delta > 0 ? ChannelHeightDelta : -ChannelHeightDelta);
                e.Handled = true;
            }
            else if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
            {
                if (!(sender is ScrollViewer scroll)) return;
                scroll.ScrollToVerticalOffset(scroll.VerticalOffset - e.Delta);
                e.Handled = true;
            }
        }

19 Source : EventToCommandBehavior.cs
with MIT License
from ABTSoftware

private void ExecuteCommand(object sender, EventArgs e)
        {
            object parameter = this.PreplacedArguments ? e : null;
            if (this.Command != null)
            {
                if (this.Command.CanExecute(parameter))
                    this.Command.Execute(parameter);
            }
        }

19 Source : SettingItem.xaml.cs
with MIT License
from Accelerider

private void SettingItem_OnMouseUp(object sender, MouseButtonEventArgs e)
        {
            if (Command?.CanExecute(CommandParameter) ?? false) Command.Execute(CommandParameter);
        }

19 Source : SearchBar.xaml.cs
with MIT License
from Accelerider

private void PART_SearchBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            var text = PART_SearchBox.Text;
            if (IsRealTimeMode &&
               !string.IsNullOrEmpty(text) &&
               SearchCommand.CanExecute(text))
            {
                SearchCommand.Execute(text);
            }
        }

19 Source : CommandExtensions.cs
with MIT License
from Accelerider

public static void Invoke(this ICommand @this, object parameter = null)
        {
            if (@this != null && @this.CanExecute(parameter)) @this.Execute(parameter);
        }

19 Source : EventToCommand.cs
with GNU General Public License v3.0
from aduskin

protected override void Invoke(object parameter)
        {
            if (replacedociatedElementIsDisabled() && !AlwaysInvokeCommand)
                return;
            var command = GetCommand();
            var parameter1 = CommandParameterValue;
            if (parameter1 == null && PreplacedEventArgsToCommand)
                parameter1 = EventArgsConverter == null
                    ? parameter
                    : EventArgsConverter.Convert(parameter, EventArgsConverterParameter);
            if (command == null || !command.CanExecute(parameter1))
                return;
            command.Execute(parameter1);
        }

19 Source : EventToCommand.cs
with GNU General Public License v3.0
from aduskin

private void EnableDisableElement()
        {
            var replacedociatedObject = GetreplacedociatedObject();
            if (replacedociatedObject == null)
                return;
            var command = GetCommand();
            if (!MustToggleIsEnabledValue || command == null)
                return;
            replacedociatedObject.IsEnabled = command.CanExecute(CommandParameterValue);
        }

19 Source : InvokeCommandAction.cs
with GNU General Public License v3.0
from aduskin

protected override void Invoke(object parameter)
        {
            if (replacedociatedObject == null)
                return;
            var command = ResolveCommand();
            if (command == null || !command.CanExecute(CommandParameter))
                return;
            command.Execute(CommandParameter);
        }

19 Source : ClickBehavior.cs
with Mozilla Public License 2.0
from agebullhu

private void OnCanExecuteChanged(object sender, EventArgs e)
        {
            replacedociatedObject.IsEnabled = Command.CanExecute(CommandProperty);
        }

19 Source : ClickBehavior.cs
with Mozilla Public License 2.0
from agebullhu

private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ClickCount > 1 && !IsDoubleClick)
            {
                return;
            }
            e.Handled = true;
            ICommand cmd = Command;
            object par = CommandParameter;
            if (cmd.CanExecute(par))
            {
                cmd.CanExecute(par);
            }
        }

19 Source : CommandReference.cs
with GNU Affero General Public License v3.0
from akshinmustafayev

public bool CanExecute(object parameter)
        {
            if (Command != null)
                return Command.CanExecute(parameter);
            return false;
        }

19 Source : ListBoxExtensions.cs
with GNU General Public License v3.0
from alexdillon

private static void OnListBoxScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            var scrollViewer = (ScrollViewer)sender;
            var listBox = scrollViewer.TemplatedParent as ListBox;

            var topSnap = GetTopLoadingSnap(listBox);
            var bottomSnap = GetBottomLoadingSnap(listBox);

            if (bottomSnap > 0)
            {
                scrollViewer.UpdateLayout();
                scrollViewer.ScrollToVerticalOffset(bottomSnap);
                scrollViewer.UpdateLayout();
                SetBottomLoadingSnap(listBox, 0);
                return;
            }
            else if (topSnap != 0)
            {
                // Calculate the offset where the last message the user was looking at is
                // Scroll back to there so new messages appear on top, above screen
                scrollViewer.UpdateLayout();

                double newHeight = scrollViewer?.ExtentHeight ?? 0.0;
                double difference = newHeight - topSnap;

                scrollViewer.ScrollToVerticalOffset(difference);
                SetTopLoadingSnap(listBox, 0);
                return;
            }

            // Check to see if scrolled to top
            if (scrollViewer.VerticalOffset == 0)
            {
                var command = GetScrollToTop(listBox);
                if (command != null && command.CanExecute(null))
                {
                    // Save the original position to allow us to return to it when the UI update is completed
                    double originalHeight = scrollViewer?.ExtentHeight ?? 0.0;
                    double originalOffset = scrollViewer?.VerticalOffset ?? 0.0;

                    // Run the At-Top handler
                    scrollViewer.CanContentScroll = false;
                    SetTopLoadingSnap(listBox, (int)originalHeight);
                    command.Execute(scrollViewer);
                    scrollViewer.CanContentScroll = true;
                }
            }
            else if ((int)scrollViewer.VerticalOffset == (int)scrollViewer.ScrollableHeight)
            {
                if (e.VerticalChange < 1000)
                {
                    var command = GetScrollToBottom(listBox);
                    if (command != null && command.CanExecute(null))
                    {
                        // Save the original position to allow us to return to it when the UI update is completed
                        double originalHeight = scrollViewer?.ExtentHeight ?? 0.0;
                        double originalOffset = scrollViewer?.VerticalOffset ?? 0.0;

                        // Run the At-Bottom handler
                        scrollViewer.CanContentScroll = false;
                        SetBottomLoadingSnap(listBox, (int)originalOffset);
                        command.Execute(scrollViewer);
                        scrollViewer.CanContentScroll = true;
                    }
                }
            }
        }

19 Source : InfiniteScrollBehavior.cs
with GNU General Public License v3.0
from alexdillon

protected override void OnAttached()
        {
            base.OnAttached();

            Observable.FromEventPattern(this.replacedociatedObject, nameof(this.replacedociatedObject.LayoutUpdated))
                .Take(1)
                .Subscribe(_ =>
                {
                    var scrollViewer = this.replacedociatedObject.Scroll as ScrollViewer;

                    scrollViewer.GetObservable(ScrollViewer.VerticalScrollBarMaximumProperty)
                    .Subscribe(vscroll =>
                    {
                        this.verticalHeightMax = vscroll;

                        if (this.LockedToBottom)
                        {
                            // Scroll to bottom
                            scrollViewer.SetValue(ScrollViewer.VerticalScrollBarValueProperty, this.verticalHeightMax);
                        }
                    })
                    .DisposeWith(this.disposables);

                    scrollViewer.GetObservable(ScrollViewer.OffsetProperty)
                    .ForEachAsync(offset =>
                    {
                        if (scrollViewer.Extent.Height == 0)
                        {
                            this.LockedToBottom = scrollViewer.Bounds.Height == 0;
                        }

                        if (offset.Y <= double.Epsilon)
                        {
                            // At top
                            if (this.ReachedTopCommand.CanExecute(scrollViewer))
                            {
                                this.ReachedTopCommand.Execute(scrollViewer);
                            }
                        }

                        var delta = Math.Abs(this.verticalHeightMax - offset.Y);

                        if (delta <= double.Epsilon)
                        {
                            // At bottom
                            this.replacedociatedObject.SetValue(InfiniteScrollBehaviorPositionHelper.IsNotAtBottomProperty, false);
                            this.LockedToBottom = true;
                        }
                        else
                        {
                            // Not at bottom
                            this.replacedociatedObject.SetValue(InfiniteScrollBehaviorPositionHelper.IsNotAtBottomProperty, true);
                            this.LockedToBottom = false;
                        }
                    })
                    .DisposeWith(this.disposables);
                });
        }

19 Source : FlexLayoutTappedBehavior.cs
with MIT License
from Altevir

private void OnTapped(object sender, EventArgs e)
        {
            if (sender is BindableObject bindable && this.Command != null && this.Command.CanExecute(null))
            {
                this.Command.Execute(bindable.BindingContext);
            }
        }

19 Source : ContentDialog.cs
with MIT License
from amwx

private void HandlePrimaryClick()
		{
			var ea = new ContentDialogButtonClickEventArgs(this);
			OnPrimaryButtonClick(ea);

			if (ea.Cancel)
				return;

			result = ContentDialogResult.Primary;
			if (!ea.IsDeferred)
			{
				if (PrimaryButtonCommand != null && PrimaryButtonCommand.CanExecute(PrimaryButtonCommandParameter))
				{
					PrimaryButtonCommand.Execute(PrimaryButtonCommandParameter);
				}
				HideCore();
			}
			else
			{
				IsEnabled = false;
			}
		}

19 Source : ContentDialog.cs
with MIT License
from amwx

private void HandleSecondaryClick()
		{
			var ea = new ContentDialogButtonClickEventArgs(this);
			OnSecondaryButtonClick(ea);

			if (ea.Cancel)
				return;

			result = ContentDialogResult.Secondary;
			if (!ea.IsDeferred)
			{
				if (SecondaryButtonCommand != null && SecondaryButtonCommand.CanExecute(SecondaryButtonCommandParameter))
				{
					SecondaryButtonCommand.Execute(SecondaryButtonCommandParameter);
				}
				HideCore();
			}
			else
			{
				IsEnabled = false;
			}
		}

19 Source : ContentDialog.cs
with MIT License
from amwx

private void HandleCloseClick()
		{
			var ea = new ContentDialogButtonClickEventArgs(this);
			OnCloseButtonClick(ea);

			if (ea.Cancel)
				return;

			result = ContentDialogResult.None;
			if (!ea.IsDeferred)
			{
				if (CloseButtonCommand != null && CloseButtonCommand.CanExecute(CloseButtonCommandParameter))
				{
					CloseButtonCommand.Execute(CloseButtonCommandParameter);
				}
				HideCore();
			}
			else
			{
				IsEnabled = false;
			}
		}

19 Source : MenuFlyoutItem.cs
with MIT License
from amwx

protected virtual void OnClick()
		{
			RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent));

			if (Command?.CanExecute(CommandParameter) == true)
			{
				Command.Execute(CommandParameter);
			}
		}

19 Source : MenuFlyoutItem.cs
with MIT License
from amwx

private void CanExecuteChanged(object sender, EventArgs e)
		{
			var canExec = Command == null || Command.CanExecute(CommandParameter);

			if (canExec != _canExecute)
			{
				_canExecute = canExec;
				UpdateIsEffectivelyEnabled();
			}
		}

19 Source : XamlUICommand.cs
with MIT License
from amwx

public bool CanExecute(object param)
		{
			bool canExec = false;

			var args = new CanExecuteRequestedEventArgs(param);

			CanExecuteRequested?.Invoke(this, args);

			canExec = args.CanExecute;

			var command = Command;
			if (command != null)
			{
				bool canExecCommand = command.CanExecute(param);
				canExec = canExec && canExecCommand;
			}

			return canExec;
		}

19 Source : GridViewSorting.cs
with GNU General Public License v3.0
from AndreiFedarets

private static void OnColumnHeaderClick(object sender, RoutedEventArgs e)
        {
            GridViewColumnHeader headerClicked = e.OriginalSource as GridViewColumnHeader;
            if (headerClicked != null)
            {
                string propertyName = GetPropertyName(headerClicked.Column);
                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);
                        }
                    }
                }
            }
        }

19 Source : ControlEventCommandBehavior.cs
with GNU General Public License v3.0
from AndreiFedarets

private void UpdateEnabledStateInternal()
        {
            if (TargetObject == null)
            {
                Command = null;
                CommandParameter = null;
                return;
            }
            if (Command != null)
            {
                Control control = TargetObject;
                control.IsEnabled = Command.CanExecute(CommandParameter);
            }
        }

19 Source : EventToCommandBehavior.cs
with MIT License
from AndyCW

void OnEvent(object sender, object eventArgs)
        {
            if (Command == null)
            {
                return;
            }

            object resolvedParameter;
            if (CommandParameter != null)
            {
                resolvedParameter = CommandParameter;
            }
            else if (Converter != null)
            {
                resolvedParameter = Converter.Convert(eventArgs, typeof(object), null, null);
            }
            else
            {
                resolvedParameter = eventArgs;
            }

            if (Command.CanExecute(resolvedParameter))
            {
                Command.Execute(resolvedParameter);
            }
        }

19 Source : Entry.cs
with MIT License
from angelobelchior

private void ExecuteCompletedCommand()
        {
            if (this.CompletedCommand != null)
                if (this.CompletedCommand.CanExecute(this.CompletedCommandParameter))
                    this.CompletedCommand.Execute(this.CompletedCommandParameter);
        }

19 Source : Entry.cs
with MIT License
from angelobelchior

private void CommandCanExecuteChanged(object sender, EventArgs eventArgs)
        {
            ICommand cmd = CompletedCommand;
            if (cmd != null)
                IsEnabled = cmd.CanExecute(CompletedCommandParameter);
        }

19 Source : ListView.cs
with MIT License
from angelobelchior

private void ListView_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            if (ItemTappedCommand != null && ItemTappedCommand.CanExecute(null))
                ItemTappedCommand.Execute(e.Item);
        }

19 Source : ListView.cs
with MIT License
from angelobelchior

private void InfiniteListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)
        {
            var items = ItemsSource as IList;
            if (items != null && e.Item == items[items.Count - 3])
            {
                if (InfiniteScrollCommand != null && InfiniteScrollCommand.CanExecute(null))
                    InfiniteScrollCommand.Execute(null);
            }
        }

19 Source : Picker.cs
with MIT License
from angelobelchior

private void OnSelectedItemPropertyChanged()
        {
            if (this.ItemsSource == null) return;

            this.SelectedIndex = this.IndexOf(this.SelectedItem);
            if (this.SelectedItemChangedCommand != null && this.SelectedItemChangedCommand.CanExecute(this.SelectedItem))
                this.SelectedItemChangedCommand.Execute(this.SelectedItem);
        }

19 Source : Picker.cs
with MIT License
from angelobelchior

private void CommandCanExecuteChanged(object sender, EventArgs eventArgs)
        {
            ICommand cmd = SelectedItemChangedCommand;
            if (cmd != null)
                IsEnabled = cmd.CanExecute(this.SelectedItem);
        }

19 Source : Slider.cs
with MIT License
from angelobelchior

private void CommandCanExecuteChanged(object sender, EventArgs eventArgs)
        {
            ICommand cmd = ValueChangedCommand;
            if (cmd != null)
                IsEnabled = cmd.CanExecute(ValueChangedCommandParameter);
        }

19 Source : EventToCommandBehavior.cs
with MIT License
from anjoy8

private void OnFired(object sender, EventArgs eventArgs)
        {
            if (Command == null)
                return;

            var parameter = CommandParameter;

            if (eventArgs != null && eventArgs != EventArgs.Empty)
            {
                parameter = eventArgs;

                if (EventArgsConverter != null)
                {
                    parameter = EventArgsConverter.Convert(eventArgs, typeof(object), EventArgsConverterParameter, CultureInfo.CurrentUICulture);
                }
            }

            if (Command.CanExecute(parameter))
            {
                Command.Execute(parameter);
            }
        }

19 Source : ControlDoubleClickBehavior.cs
with Apache License 2.0
from AnkiUniversal

static void control_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var control = sender as Control;
            
            if(control != null)
            {
                var command = control.GetValue(ExecuteCommand) as ICommand;
                var commandParameter = control.GetValue(ExecuteCommandParameter);

                if (command.CanExecute(e))
                {
                    command.Execute(commandParameter);
                }
            }
        }

19 Source : ContextMenuItem.cs
with MIT License
from anpin

internal void OnItemTapped()
        {

            ItemTapped?.Invoke(this, new EventArgs());
            if (Command?.CanExecute(CommandParameter) ?? false && IsEnabled)
            {
                Command.Execute(CommandParameter);
            }
        }

19 Source : WindowClosingBehaviour.cs
with MIT License
from AntonyCorbett

private static void OnWindowClosing(object sender, CancelEventArgs e)
        {
            var closing = GetClosing(sender as Window);
            if (closing != null)
            {
                if (closing.CanExecute(null))
                {
                    closing.Execute(null);
                }
                else
                {
                    var cancelClosing = GetCancelClosing(sender as Window);
                    cancelClosing?.Execute(null);

                    e.Cancel = true;
                }
            }
        }

19 Source : ARFlatGroupAdapter.cs
with Apache License 2.0
from AppRopio

protected virtual void ExecuteCommandOnItem(ICommand command, object itemDataContext)
        {
            if (command?.CanExecute(itemDataContext) == true && itemDataContext != null)
            {
                command.Execute(itemDataContext);
            }
        }

19 Source : BaseCollectionViewSource.cs
with Apache License 2.0
from AppRopio

public override void WillDisplayCell(UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
        {
            if ((indexPath.Row >= (ItemsSource.Count() - FromBottomCellStartLoadingIndex)) && MoreCommand != null && MoreCommand.CanExecute(null))
                MoreCommand.Execute(null);
        }

19 Source : BaseTableViewSource.cs
with Apache License 2.0
from AppRopio

public override void WillDisplay(UITableView tableView, UITableViewCell cell, NSIndexPath indexPath)
        {
            if ((indexPath.Row >= (ItemsSource.Count() - FromBottomCellStartLoadingIndex)) &&
                LoadMoreCommand != null && LoadMoreCommand.CanExecute(null))
            {
                LoadMoreCommand.Execute(null);
            }
        }

19 Source : BindableWebVIew.cs
with Apache License 2.0
from AppRopio

private void HandleLoadFinished(object sender, EventArgs ev)
        {
            var url = Url?.ToString();

            var command = this.LoadFinishedCommand;
            if (command != null && command.CanExecute(url))
                command.Execute(url);
        }

19 Source : ARLinearLayoutAdapter.cs
with Apache License 2.0
from AppRopio

public void OnClick(View view)
        {
            if (view?.Tag is IMvxLisreplacedemView mvxLisreplacedemView && (ItemClick?.CanExecute(mvxLisreplacedemView.DataContext) ?? false))
            {
                ItemClick?.Execute(mvxLisreplacedemView.DataContext);
            }
        }

19 Source : ARSimpleFragmentPagerAdapter.cs
with Apache License 2.0
from AppRopio

protected virtual void ExecuteCommandOnItem(ICommand command, object dataContext)
        {
            if (command == null)
                return;

            var item = dataContext;
            if (item == null)
                return;

            if (!command.CanExecute(item))
                return;

            command.Execute(item);
        }

19 Source : ARViewPager.cs
with Apache License 2.0
from AppRopio

protected virtual void ExecuteCommand(ICommand command, object parameter)
        {
            if (command == null)
                return;

            if (!command.CanExecute(parameter))
                return;

            command.Execute(parameter);
        }

19 Source : BindableMKMapView.cs
with Apache License 2.0
from AppRopio

protected void OnItemSelected(T item)
        {
            SelectedItem = item;

            if (SelectionChangedCommand != null && SelectionChangedCommand.CanExecute(item))
                SelectionChangedCommand.Execute(item);
        }

19 Source : BasketTableSource.cs
with Apache License 2.0
from AppRopio

public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
        {
            if (editingStyle == UITableViewCellEditingStyle.Delete && DeleteItemCommand != null)
            {
                var item = GereplacedemAt(indexPath) as IBaskereplacedemVM;
                if (item != null && DeleteItemCommand.CanExecute(item))
                    DeleteItemCommand.Execute(item);
            }
        }

19 Source : LinkerPleaseInclude.cs
with Apache License 2.0
from AppRopio

public void Include(ICommand command)
        {
            command.CanExecuteChanged += (s, e) => { if (command.CanExecute(null)) command.Execute(null); };
        }

19 Source : AudioPostControl.xaml.cs
with Apache License 2.0
from artemshuba

private void TracksListView_ItemClick(object sender, ItemClickEventArgs e)
        {
            var track = (IAudio)e.ClickedItem;
            var container = new AudioContainer() { Track = track, Tracklist = AudioPost.Tracks };

            if (Command?.CanExecute(container) == true)
                Command?.Execute(container);
        }

19 Source : AudioPostControl.xaml.cs
with Apache License 2.0
from artemshuba

private void AuthorNameButton_Click(object sender, RoutedEventArgs e)
        {
            if (AuthorCommand?.CanExecute(AudioPost) == true)
                AuthorCommand?.Execute(AudioPost);
        }

19 Source : AudioPostControl.xaml.cs
with Apache License 2.0
from artemshuba

private void PostDateButton_Click(object sender, RoutedEventArgs e)
        {
            if (PostCommand?.CanExecute(AudioPost) == true)
                PostCommand?.Execute(AudioPost);
        }

19 Source : TrackControl.xaml.cs
with Apache License 2.0
from artemshuba

private void TrackControl_OnTapped(object sender, TappedRoutedEventArgs e)
        {
            if (Command?.CanExecute(CommandParameter) == true)
                Command?.Execute(CommandParameter);
        }

See More Examples