2015-06-19 56 views
0

我正在为Windows Phone 8.1制作通用应用程序,并遇到了我的代码问题。C#可见不起作用

在TextBlock值变得大于或等于22之后,一些图像应该变为可见。如果该值小于22,则所有图像都不可见。

我的问题:我如何正文块值> = “22” 后获得可见光图像

这是我的代码隐藏图片:

private void points_Loaded(object sender, RoutedEventArgs e) 
{ 
    int n = 0; 
    bool b = int.TryParse(points.Text, out n); 
    DataContext = this; 
    ImageVis = (b && n >= 22) ? Visibility.Visible : isibility.Collapsed; 
} 

private Visibility imageVis; 

public Visibility ImageVis 
{ 
    get { return imageVis; } 
    set 
    { 
    imageVis = value; 
    RaisePropertyChanged("ImageVis"); 
    } 
} 

public event PropertyChangedEventHandler PropertyChanged = delegate { }; 

protected void RaisePropertyChanged(string propertyName) 
{ 
    PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
} 

这部分代码是从XAML:

<Image x:Name="hole17img" 
    HorizontalAlignment="Left" 
    Height="57" 
    Margin="10,3540,0,0" 
    VerticalAlignment="Top" 
    Width="380" 
    Source="Assets/septinpatsmit.png" 
    Stretch="Fill" 
    Visibility="{Binding ImageVis, Mode=TwoWay}"/> 

我有一个问题:RaisePropertyChanged("ImageVis");

'RaisePropertyChanged'在当前上下文中不存在

这是否意味着我用这个名称做了一些对象?或者是其他东西?

我可以提供我的My application,所以你可以看到发生了什么。

My application sample

回答

1

RaisePropertyChanged是MVVM光的方法,使每当你提出给定name.In属性更新XAML代码背后UI,你绑定视图模型的属性,以XAML属性和RaisePropertyChanged触发时,它通知给财产和用户界面刷新后。

您还需要使用转换器将布尔转换为可见性。一般来说,您需要更多的Windows项目的MVVM模式知识。

看这个职位 http://www.mvvmlight.net/doc/