我看了几个有关这个问题的问题,但没有得到正确的答案。我不知道以下代码哪里出错了。我绑定了TextBlock的可见性属性,但它不起作用。这是我的xaml代码,我在按钮单击时更改TextBlock的可见性属性。
<TextBlock Visibility="{Binding IsVisible}" Text="Visibility Sample" Margin="12,40" HorizontalAlignment="Center" Name="visibilityTextblock"/>
<Button Content="visibility" Tap="Button_Tap_1"/>
这是我的
Button_Tap_1
函数。private void Button_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
IsVisible = Visibility.Visible;
}
这是我的
IsVisible
属性。private Visibility _isVisible;
public Visibility IsVisible
{
get
{
return _isVisible;
}
set
{
_isVisible = value;
NotifyPropertyChanged("IsVisible");
}
}
最后,这里是我写的NotifyPropertyChanged
方法。
#region NotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string p)
{
if (PropertyChanged == null)
return;
PropertyChanged(this, new PropertyChangedEventArgs(p));
}
#endregion
默认情况下,我通过更改文本块属性将其可见性初始化为折叠状态,如下所示:
IsVisible = Visibility.Collapsed; ( in the constructor)
我也从INotifyPropertyChanged
接口派生,并在同一个类文件中实现了所有这些内容。有人能帮我找出问题所在吗?