52 lines
1.1 KiB
C#
52 lines
1.1 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
namespace ConeCalorimeter.ViewModels;
|
|
|
|
public sealed class ReportFieldViewModel : ObservableObject
|
|
{
|
|
private string _value;
|
|
private bool _isAutoFilled;
|
|
private bool _isSettingAutoValue;
|
|
|
|
public ReportFieldViewModel(string key, string label, string value = "")
|
|
{
|
|
Key = key;
|
|
Label = label;
|
|
_value = value;
|
|
}
|
|
|
|
public string Key { get; }
|
|
|
|
public string Label { get; }
|
|
|
|
public string Value
|
|
{
|
|
get => _value;
|
|
set
|
|
{
|
|
if (SetProperty(ref _value, value) && !_isSettingAutoValue)
|
|
{
|
|
_isAutoFilled = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetAutoValue(string value, bool overwriteManual = false)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!overwriteManual && !string.IsNullOrWhiteSpace(Value) && !_isAutoFilled)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_isSettingAutoValue = true;
|
|
Value = value;
|
|
_isSettingAutoValue = false;
|
|
_isAutoFilled = true;
|
|
}
|
|
}
|