Skip to content

657 keybinding issue when attaching it to windows with commands with canexecute methods #971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/Caliburn.Micro.Platform/ActionExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
/// <summary>
/// The context used during the execution of an Action or its guard.
/// </summary>
public class ActionExecutionContext : IDisposable {
public class ActionExecutionContext : IDisposable
{
private WeakReference _message;
private WeakReference _source;
private WeakReference _target;
Expand All @@ -51,6 +52,8 @@
/// </summary>
public object EventArgs;

public bool IgnoreGuard { get; set; }

Check warning on line 55 in src/Caliburn.Micro.Platform/ActionExecutionContext.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionExecutionContext.IgnoreGuard'

Check warning on line 55 in src/Caliburn.Micro.Platform/ActionExecutionContext.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionExecutionContext.IgnoreGuard'

Check warning on line 55 in src/Caliburn.Micro.Platform/ActionExecutionContext.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionExecutionContext.IgnoreGuard'

Check warning on line 55 in src/Caliburn.Micro.Platform/ActionExecutionContext.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionExecutionContext.IgnoreGuard'

Check warning on line 55 in src/Caliburn.Micro.Platform/ActionExecutionContext.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionExecutionContext.IgnoreGuard'

Check warning on line 55 in src/Caliburn.Micro.Platform/ActionExecutionContext.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionExecutionContext.IgnoreGuard'

Check warning on line 55 in src/Caliburn.Micro.Platform/ActionExecutionContext.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionExecutionContext.IgnoreGuard'

Check warning on line 55 in src/Caliburn.Micro.Platform/ActionExecutionContext.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionExecutionContext.IgnoreGuard'

Check warning on line 55 in src/Caliburn.Micro.Platform/ActionExecutionContext.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionExecutionContext.IgnoreGuard'

Check warning on line 55 in src/Caliburn.Micro.Platform/ActionExecutionContext.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionExecutionContext.IgnoreGuard'

Check warning on line 55 in src/Caliburn.Micro.Platform/ActionExecutionContext.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionExecutionContext.IgnoreGuard'

Check warning on line 55 in src/Caliburn.Micro.Platform/ActionExecutionContext.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionExecutionContext.IgnoreGuard'

/// <summary>
/// The actual method info to be invoked.
/// </summary>
Expand All @@ -59,31 +62,35 @@
/// <summary>
/// The message being executed.
/// </summary>
public ActionMessage Message {
public ActionMessage Message
{
get { return _message == null ? null : _message.Target as ActionMessage; }
set { _message = new WeakReference(value); }
}

/// <summary>
/// The source from which the message originates.
/// </summary>
public FrameworkElement Source {
public FrameworkElement Source
{
get { return _source == null ? null : _source.Target as FrameworkElement; }
set { _source = new WeakReference(value); }
}

/// <summary>
/// The instance on which the action is invoked.
/// </summary>
public object Target {
public object Target
{
get { return _target == null ? null : _target.Target; }
set { _target = new WeakReference(value); }
}

/// <summary>
/// The view associated with the target.
/// </summary>
public DependencyObject View {
public DependencyObject View
{
get { return _view == null ? null : _view.Target as DependencyObject; }
set { _view = new WeakReference(value); }
}
Expand All @@ -93,8 +100,10 @@
/// </summary>
/// <param name="key">The data key.</param>
/// <returns>Custom data associated with the context.</returns>
public object this[string key] {
get {
public object this[string key]
{
get
{
if (_values == null)
_values = new Dictionary<string, object>();

Expand All @@ -103,7 +112,8 @@

return result;
}
set {
set
{
if (_values == null)
_values = new Dictionary<string, object>();

Expand All @@ -114,7 +124,8 @@
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose() {
public void Dispose()
{
Disposing(this, System.EventArgs.Empty);
}

Expand Down
30 changes: 25 additions & 5 deletions src/Caliburn.Micro.Platform/ActionMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
set { SetValue(MethodNameProperty, value); }
}

public bool IgnoreGuard { get; set; }

Check warning on line 164 in src/Caliburn.Micro.Platform/ActionMessage.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionMessage.IgnoreGuard'

Check warning on line 164 in src/Caliburn.Micro.Platform/ActionMessage.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionMessage.IgnoreGuard'

Check warning on line 164 in src/Caliburn.Micro.Platform/ActionMessage.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionMessage.IgnoreGuard'

Check warning on line 164 in src/Caliburn.Micro.Platform/ActionMessage.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionMessage.IgnoreGuard'

Check warning on line 164 in src/Caliburn.Micro.Platform/ActionMessage.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionMessage.IgnoreGuard'

Check warning on line 164 in src/Caliburn.Micro.Platform/ActionMessage.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionMessage.IgnoreGuard'

Check warning on line 164 in src/Caliburn.Micro.Platform/ActionMessage.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionMessage.IgnoreGuard'

Check warning on line 164 in src/Caliburn.Micro.Platform/ActionMessage.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ActionMessage.IgnoreGuard'

/// <summary>
/// Gets the parameters to pass as part of the method invocation.
/// </summary>
Expand Down Expand Up @@ -315,8 +317,9 @@
Log.Info($"Binding {binding.Source}");

#elif (NET || CAL_NETCORE) && !WinUI3 && !WINDOWS_UWP
var binding = new Binding {
Path = new PropertyPath(Message.HandlerProperty),
var binding = new Binding
{
Path = new PropertyPath(Message.HandlerProperty),
Source = currentElement
};
#elif WINDOWS_UWP || WinUI3
Expand Down Expand Up @@ -365,7 +368,8 @@
_context = new ActionExecutionContext
{
Message = this,
Source = AssociatedObject
Source = AssociatedObject,
IgnoreGuard = IgnoreGuard
};

PrepareContext(_context);
Expand Down Expand Up @@ -528,15 +532,30 @@
Log.Info($"context.CanExecute is null {context.CanExecute == null} ");
if (context.CanExecute != null)
{
Log.Info("HERE");
Log.Info($"ApplyAvailabilityEffect CanExecute {context.Method.Name}");
source.IsEnabled = context.CanExecute();
}
#else
if (!hasBinding && context.CanExecute != null)
{
Log.Info($"ApplyAvailabilityEffect CanExecute {context.CanExecute()} - {context.Method.Name}");
source.IsEnabled = context.CanExecute();
if (!context.IgnoreGuard)
{
Log.Info($"ApplyAvailabilityEffect CanExecute {context.CanExecute()} - {context.Method.Name} - {source.Name}");
source.IsEnabled = context.CanExecute();
}
else
{
Log.Info("Skipping IsEnabled source because source Name is not set");
}
if (!source.IsEnabled)
{
Log.Info($"Disabled {source.Name}");
}
else
{
Log.Info($"Enabled {source.Name}");
}
}
#endif
Log.Info($"ApplyAvailabilityEffect source enabled {source.IsEnabled}");
Expand Down Expand Up @@ -615,6 +634,7 @@
}
}
#else

if (source != null && source.DataContext != null)
{
var target = source.DataContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public ActionMessage()
/// <value>The name of the method.</value>
public string MethodName { get; set; }

public bool IgnoreGuard { get; set; }
/// <summary>
/// The handler for the action.
/// </summary>
Expand Down
Loading