validation

This commit is contained in:
Paul Schneider 2016-12-10 23:20:13 +01:00
commit 8db905a90e
4 changed files with 48 additions and 17 deletions

View file

@ -24,7 +24,15 @@ namespace BookAStar.ViewModels.EstimateAndBilling
{
SyncData();
}
public override void OnViewAppearing()
{
base.OnViewAppearing();
SyncData();
}
/// <summary>
/// Called to synchronyze this view on target model,
/// at accepting a new representation for this model
/// </summary>
private void SyncData()
{
if (Data.AttachedFiles == null) Data.AttachedFiles = new List<string>();
@ -41,12 +49,13 @@ namespace BookAStar.ViewModels.EstimateAndBilling
NotifyPropertyChanged("FormattedTotal");
NotifyPropertyChanged("Query");
NotifyPropertyChanged("CLient");
NotifyPropertyChanged("ModelState");
}
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.PropertyName == "Data")
if (e.PropertyName.StartsWith("Data"))
{
SyncData();
}
@ -61,6 +70,7 @@ namespace BookAStar.ViewModels.EstimateAndBilling
Data.Bill = Bill.Select(l => l.Data).ToList();
NotifyPropertyChanged("FormattedTotal");
NotifyPropertyChanged("Bill");
NotifyPropertyChanged("ViewModelState");
}
[JsonIgnore]
@ -127,7 +137,7 @@ namespace BookAStar.ViewModels.EstimateAndBilling
get
{
OnPlatform<Font> lfs = (OnPlatform<Font>)App.Current.Resources["MediumFontSize"];
OnPlatform<Color> etc = (OnPlatform<Color>)App.Current.Resources["EmphasisTextColor"];
Color etc = (Color) App.Current.Resources["EmphasisTextColor"];
return new FormattedString
{
@ -135,7 +145,7 @@ namespace BookAStar.ViewModels.EstimateAndBilling
Spans = {
new Span { Text = "Total TTC: " },
new Span { Text = Data.Total.ToString(),
ForegroundColor = etc.Android ,
ForegroundColor = etc,
FontSize = (double) lfs.Android.FontSize },
new Span { Text = "€", FontSize = (double) lfs.Android.FontSize }
}

View file

@ -1,12 +1,7 @@
using BookAStar.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System;
using XLabs.Forms.Mvvm;
using System.ComponentModel;
using Newtonsoft.Json;
namespace BookAStar.ViewModels.Validation
{
@ -16,7 +11,7 @@ namespace BookAStar.ViewModels.Validation
/// </summary>
public class EditingViewModel<DataType>: ViewModel
{
[JsonIgnore]
public Action<DataType, ModelState> CheckCommand { set; get; }
public DataType Data { get; set; }
@ -44,13 +39,16 @@ namespace BookAStar.ViewModels.Validation
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
Check();
}
public virtual void Check()
{
if (CheckCommand != null)
{
ViewModelState.Clear();
CheckCommand(Data, ViewModelState);
}
}
/* NOTE : I had a dream.
bool existsRemotely;