我有一个图像我可以绑定到XAML的图像属性,问题是,当我弹出我的视图我希望图像保持不可见,然后当我点击我的按钮再次出现到目前为止,我在m ViewModel中得到了这个:
private string imageSource;
public string ImageSource
{
get { return imageSource; }
set { imageSource = value; Notify("ImageSource"); }
}
public bool State { get { return false; }}
private Image visibleImage;
public Image VisibleImage
{
get { return new Image {IsVisible = State,Source = ImageSource }; }
set { visibleImage = value; Notify("VisibleImage"); Notify("State"); }
}
在我的BindingContext
属性IsVisible被设置为false,但不工作!
您可以通过完全避免在视图模型中保留Image
引用来简化示例。像这样修改你的State
标志:
private boolean _state;
public boolean State {
get { return _state; }
set { _state = value; Notify("State"); }
}
在XAML中声明Image
及其源和可见性绑定:
<Image Source="{Binding ImageSource}" IsVisible="{Binding State}" />
初始化视图模型时,将State
设置为false
。然后单击按钮需要将标志设置为true
以使图像可见。