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 关注
- 77 浏览
添加回答
举报