【发布时间】:2017-10-05 03:38:17
【问题描述】:
我在 xmal 中有一个 StackLayout 属性,如下所示:
<StackLayout x:Name="_infoView"
Margin="0,10,0,10"
BackgroundColor="Black"
IsVisible="{Binding State}"/>
以及 ViewModel 中的绑定 bool 变量
private Boolean _state = true;
public Boolean State
{
get { return _state; }
set { }
}
我的 xmal 中有一个按钮,想控制 StackLayout 的可见性,所以我做了这样的事情:
<Button x:Name="CloseButton"
Grid.Row="0"
Grid.Column="3"
Command="{Binding CloseWindowCommand}"/>
在 ViewModel 中
CloseWindowCommand = new Command(CloseWindowTapped, CanCloseWindowTapped);
public ICommand CloseWindowCommand { get; set; }
public void CloseWindowTapped()
{
State = false;
}
public bool CanCloseWindowTapped()
{
return true;
}
我假设,通过点击 CloseButton,我的 StackLayout 会消失...但它不起作用
【问题讨论】:
标签: c# xaml mvvm data-binding