mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 22:23:29 -07:00
remove the strong reference carried from delegate (#32)
This commit is contained in:
parent
af90e39029
commit
27abae0099
5 changed files with 28 additions and 8 deletions
|
@ -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);
|
||||
|
@ -17,7 +17,7 @@ namespace CalculatorApp.Utils
|
|||
TTarget thatTarget = weakTarget.Target as TTarget;
|
||||
if(null != thatTarget)
|
||||
{
|
||||
handler.Invoke(param);
|
||||
handler.Invoke(thatTarget, param);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -141,7 +141,11 @@ namespace CalculatorApp
|
|||
{
|
||||
if (donotuse_HistoryButtonPressed == null)
|
||||
{
|
||||
donotuse_HistoryButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this, ToggleHistoryFlyout);
|
||||
donotuse_HistoryButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this,
|
||||
(that, param) =>
|
||||
{
|
||||
that.ToggleHistoryFlyout(param);
|
||||
});
|
||||
}
|
||||
return donotuse_HistoryButtonPressed;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,11 @@ namespace CalculatorApp
|
|||
{
|
||||
if (donotuse_ButtonPressed == null)
|
||||
{
|
||||
donotuse_ButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this, OnAngleButtonPressed);
|
||||
donotuse_ButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this,
|
||||
(that, param)=>
|
||||
{
|
||||
that.OnAngleButtonPressed(param);
|
||||
});
|
||||
}
|
||||
return donotuse_ButtonPressed;
|
||||
}
|
||||
|
|
|
@ -115,7 +115,11 @@ namespace CalculatorApp
|
|||
{
|
||||
if (donotuse_ZoomOutButtonPressed == null)
|
||||
{
|
||||
donotuse_ZoomOutButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this, OnZoomOutCommand);
|
||||
donotuse_ZoomOutButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this,
|
||||
(that, param) =>
|
||||
{
|
||||
that.OnZoomOutCommand(param);
|
||||
});
|
||||
}
|
||||
return donotuse_ZoomOutButtonPressed;
|
||||
}
|
||||
|
@ -128,7 +132,11 @@ namespace CalculatorApp
|
|||
{
|
||||
if (donotuse_ZoomInButtonPressed == null)
|
||||
{
|
||||
donotuse_ZoomInButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this, OnZoomInCommand);
|
||||
donotuse_ZoomInButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this,
|
||||
(that, param) =>
|
||||
{
|
||||
that.OnZoomInCommand(param);
|
||||
});
|
||||
}
|
||||
return donotuse_ZoomInButtonPressed;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using System.Windows.Input;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
@ -17,7 +17,11 @@ namespace CalculatorApp
|
|||
{
|
||||
if (donotuse_BitLengthButtonPressed == null)
|
||||
{
|
||||
donotuse_BitLengthButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this, OnBitLengthButtonPressed);
|
||||
donotuse_BitLengthButtonPressed = DelegateCommandUtils.MakeDelegateCommand(this,
|
||||
(that, param) =>
|
||||
{
|
||||
that.OnBitLengthButtonPressed(param);
|
||||
});
|
||||
}
|
||||
return donotuse_BitLengthButtonPressed;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue