The Model (MVVM) of a DialogViewAdapter takes care of updating the variables through OnPropertyChanged inside of the DialogView. However to code repeat itself 8 times, so I must be thinking there needs to be a smarter solution to reduce the code size. The code is exactly the same, except for the variableNames.
using System;
using VisiWin.ApplicationFramework;
namespace HMI.Views.DialogRegion
{
/// <summary>
/// The Model of CustomControl: Can contain everything you need
/// Used for the bindings in CustomFFUDialogView
/// </summary>
[ExportAdapter("CustomFFUAdapter")]
public class CustomFFUAdapter : CordisAdapter
{
// Change value: oActualVelocity on Property Change
private string oactualVelocity;
public string oActualVelocity
{
get { return oactualVelocity; }
set
{
if (!String.IsNullOrEmpty(oactualVelocity) && oactualVelocity.Equals(value))
return;
oactualVelocity = value;
OnPropertyChanged(nameof(oActualVelocity));
}
}
// Change value: sSetpointVelocity on Property Change
private string ssetpointVelocity;
public string sSetpointVelocity
{
get { return ssetpointVelocity; }
set
{
if (!String.IsNullOrEmpty(ssetpointVelocity) && ssetpointVelocity.Equals(value))
return;
ssetpointVelocity = value;
OnPropertyChanged(nameof(sSetpointVelocity));
}
}
private string cmdsetSetpoint;
public string cmdSetSetpoint
{
get { return cmdsetSetpoint; }
set
{
if (!String.IsNullOrEmpty(cmdsetSetpoint) && cmdsetSetpoint.Equals(value))
return;
cmdsetSetpoint = value;
OnPropertyChanged(nameof(cmdSetSetpoint));
}
}
// + 5 other Get Set OnPropertyChange calls....
}
}
I have tryed this so far:
[ExportAdapter("CustomControlAdapter")]
public class CustomControlAdapter : CordisAdapter
{
public IVariableService variableService { get; }
public CustomControlAdapter()
{
oActualVelocity = new CustomField();
cmdReset = new CustomField();
}
// Change value: oActualVelocity on Property Change
public class CustomField : AdapterBase
{
private string _address;
public CustomField()
{
}
public string Address
{
get { return _address; }
set
{
if (!String.IsNullOrEmpty(_address) && _address.Equals(value))
return;
_address = value;
OnPropertyChanged(nameof(Address));
}
}
public override string ToString()
{
return _address;
}
}
public CustomField oActualVelocity;
public CustomField cmdReset;
}
}