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;
? ? ? ? ? ?}
? ? ? ? }) ;
? ? }
}
- 1 回答
- 0 關注
- 102 瀏覽
添加回答
舉報