タイトルの意味は次のとおりです。入力が範囲(この場合は0〜10)にあるかどうかをチェックし、エントリの背景色を赤くする動作(Validatorと呼ばれます)にバインドされた "IsValid"(bool)というプロパティを持つエントリがありますまたは透明である。それはうまく動作します。しかし、ViewModelに同じロジックがあり(入力が範囲内にあるかどうかを確認するため)、ダイアログメッセージが表示されない場合は、バリデータのIsValidに直接バインドして、viewModelでbinddを使用したい(IsBinReferenceValid )abdはvmからlocigを削除します。現在、私のVM IsBinReferenceValidのプロパティは、バインディングが機能しないことを示す方法で変更されていません。問題はどこから来ていることがある場合つまり、(、同時にプロパティを参照してバインドする方法は?
<userControl:DetailedEntry
PlaceholderLabel="{x:Static locale:BinPrintLang.BinRef}"
Text="{Binding BinTextEntry}"
TextColor="{StaticResource PrimaryColor}"
BgColor="White"
BorderColor="{StaticResource DisableColor}"
VerticalOptions="CenterAndExpand"
IsLabelVisible="True"
Label="Bin Reference"
IsImportant="True"
IsValid="{Binding Source={x:Reference InputLengthValidator}, Path=IsValid}">
<userControl:DetailedEntry.EntryBehavior>
<ui:InputLengthValidator x:Name="InputLengthValidator"
MinValue="0"
MaxValue="10"
IsValid="{Binding Source=IsBinReferenceValid, Mode=OneWayToSource}"/>
</userControl:DetailedEntry.EntryBehavior>
</userControl:DetailedEntry>
私は同時に参照すると、プロパティにバインドすることができますどのように任意のアイデアことも可能である。ここでは
は、XAMLコードであります)?
ベースのバリコード:
public class ValueInRangeValidator : Validator<Entry>
{
private static BindableProperty MinValueProperty =
BindableProperty.Create("MinValue", typeof(decimal?), typeof(ValueInRangeValidator));
public decimal? MinValue
{
get { return (decimal?) GetValue(MinValueProperty); }
set
{
SetValue(MinValueProperty, value);
OnPropertyChanged();
}
}
public static BindableProperty MaxValueProperty =
BindableProperty.Create("MaxValue", typeof(decimal?), typeof(ValueInRangeValidator));
public decimal? MaxValue
{
get { return (decimal?) GetValue(MaxValueProperty); }
set
{
SetValue(MaxValueProperty, value);
OnPropertyChanged();
}
}
public virtual void Bindable_TextChanged(object sender, TextChangedEventArgs e)
{
decimal i = 0;
IsValid = decimal.TryParse(e.NewTextValue, out i);
IsValid = IsValid && (MinValue == null ? i >= decimal.MinValue : i >= MinValue);
IsValid = IsValid && (MaxValue == null ? i <= decimal.MaxValue : i <= MaxValue);
}
protected override void OnAttachedTo(Entry bindable)
{
bindable.TextChanged += Bindable_TextChanged;
}
protected override void OnDetachingFrom(Entry bindable)
{
bindable.TextChanged -= Bindable_TextChanged;
}
}
InputLengthValidatorコード:
public class InputLengthValidator : ValueInRangeValidator
{
public override void Bindable_TextChanged(object sender, TextChangedEventArgs e)
{
var max = (int) MaxValue;
var min = (int) MinValue;
var textLenght = e.NewTextValue.Length;
IsValid = textLenght >= min && textLenght < max;
}
}
問題のあなたの行動のロジックを追加します。 –
@ZiyadGodilコードを追加しました。ありがとうございます –
unfocusに表示ダイアログ(有効でない場合)したいですか? –