亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當輸入字段不可見時,如何隱藏 Xamarin 表單中的錯誤標簽?

當輸入字段不可見時,如何隱藏 Xamarin 表單中的錯誤標簽?

C#
qq_花開花謝_0 2023-09-16 15:49:25
我正在嘗試創建一個存在驗證錯誤的登錄頁面?,F在,如果輸入字段不可見,也會出現驗證錯誤。當輸入字段不可見時,如何隱藏錯誤標簽?如下圖: PIN 輸入字段在登錄頁面上不可見,但錯誤消息:Pin is required,突出顯示。請問有人可以建議一個解決方法嗎?
查看完整描述

1 回答

?
米琪卡哇伊

TA貢獻1998條經驗 獲得超6個贊

您可以使用數據綁定將IsVisibleof 標簽綁定到視圖模型中的屬性。


<Label Text="Pin is required!"? TextColor="Red"? HorizontalTextAlignment="Center" IsVisible="{Binding isVisible}"/>


<Button Text="sign in" BackgroundColor="Red" TextColor="White" Command="{Binding ClickCommand}"? WidthRequest="200" />

在你的視圖模型中

public class YourViewModel: INotifyPropertyChanged

{

? ? public event PropertyChangedEventHandler PropertyChanged;


? ? protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = "")

? ? {

? ? ? ? PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

? ? }


? ? public ICammand ClickCommand {get; set;}



? ? private bool isvisible;


? ? public bool isVisible

? ? {

? ? ?get

? ? ?{

? ? ? ? return isvisible;

? ? ?}


? ? ?set

? ? ?{

? ? ? if (isvisible!= value)

? ? ? {

? ? ? ? isvisible= value;

? ? ? ? NotifyPropertyChanged();

? ? ? }

? ? }



? ? public YourViewModel()

? ? {

? ? ? ? //...?

? ? ? ? isVisible = true; //show the label in default

? ? ? ? ?

? ? ? ? ClickCommand = new Command(() =>

? ? ? ? {

? ? ? ? ? ?if(xxx)

? ? ? ? ? ?{

? ? ? ? ? ? ? isVisible =false;

? ? ? ? ? ?}

? ? ? ? ? ?

? ? ? ? ? ?else

? ? ? ? ? ?{?

? ? ? ? ? ? ? isVisible =true;

? ? ? ? ? ?}

? ? ? ? }) ;


? ? }


}


查看完整回答
反對 回復 2023-09-16
  • 1 回答
  • 0 關注
  • 102 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號