Skip to content
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

remove the strong reference carried from delegate #32

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/Calculator/Utils/DelegateCommandUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace CalculatorApp.Utils
{
static class DelegateCommandUtils
{
public static DelegateCommand MakeDelegateCommand<TTarget>(TTarget target, DelegateCommandHandler handler)
public static DelegateCommand MakeDelegateCommand<TTarget>(TTarget target, Action<TTarget, object> handler)
where TTarget : class
{
WeakReference weakTarget = new WeakReference(target);
Expand All @@ -17,7 +17,7 @@ public static DelegateCommand MakeDelegateCommand<TTarget>(TTarget target, Deleg
TTarget thatTarget = weakTarget.Target as TTarget;
if(null != thatTarget)
{
handler.Invoke(param);
handler.Invoke(thatTarget, param);
}
});
}
Expand Down
6 changes: 5 additions & 1 deletion src/Calculator/Views/Calculator.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ public System.Windows.Input.ICommand HistoryButtonPressed
{
if (donotuse_HistoryButtonPressed == null)
{
donotuse_HistoryButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this, ToggleHistoryFlyout);
donotuse_HistoryButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this,
(that, param) =>
{
that.ToggleHistoryFlyout(param);
});
}
return donotuse_HistoryButtonPressed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ public System.Windows.Input.ICommand ButtonPressed
{
if (donotuse_ButtonPressed == null)
{
donotuse_ButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this, OnAngleButtonPressed);
donotuse_ButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this,
(that, param)=>
{
that.OnAngleButtonPressed(param);
});
}
return donotuse_ButtonPressed;
}
Expand Down
12 changes: 10 additions & 2 deletions src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ public System.Windows.Input.ICommand ZoomOutButtonPressed
{
if (donotuse_ZoomOutButtonPressed == null)
{
donotuse_ZoomOutButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this, OnZoomOutCommand);
donotuse_ZoomOutButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this,
(that, param) =>
{
that.OnZoomOutCommand(param);
});
}
return donotuse_ZoomOutButtonPressed;
}
Expand All @@ -128,7 +132,11 @@ public System.Windows.Input.ICommand ZoomInButtonPressed
{
if (donotuse_ZoomInButtonPressed == null)
{
donotuse_ZoomInButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this, OnZoomInCommand);
donotuse_ZoomInButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this,
(that, param) =>
{
that.OnZoomInCommand(param);
});
}
return donotuse_ZoomInButtonPressed;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;
using System.Windows.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand All @@ -17,7 +17,11 @@ public ICommand BitLengthButtonPressed
{
if (donotuse_BitLengthButtonPressed == null)
{
donotuse_BitLengthButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this, OnBitLengthButtonPressed);
donotuse_BitLengthButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this,
(that, param) =>
{
that.OnBitLengthButtonPressed(param);
});
}
return donotuse_BitLengthButtonPressed;
}
Expand Down