2015-06-19 96 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/