2013-08-26 4 views
0

UserControl과 페이지로드간에 비트 맵 이미지가 동적으로 변경되는 문제가 있습니다.동적으로 비트 맵 이미지 변경

디스패처 타이머를 사용하여 이미지를 변경하지 않습니다. 그러나 그것은 작동하지 않습니다. 오류는 내 uriSource가 null임을 나타냅니다.

<Image x:Name="img"> 
     <Image.Source> 
      <BitmapImage UriSource="{Binding Path=BitmapImage}" /> 
     </Image.Source> 
    </Image> 

코드의 UserControl에서 : 페이지로드에서

 public BitmapImage BitmapImage 
     { 
      get { return _bitmapImage; } 
      set 
      { 
       if (_bitmapImage == value) return; 
       _bitmapImage = value; 
       RaisePropertyChanged("BitmapImage"); 
      } 
     } 

    public event PropertyChangedEventHandler PropertyChanged; 

    private void RaisePropertyChanged(string propertyName) 
    { 
     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
     } 
    } 

코드 :

나는 MS 비주얼 스튜디오 2012, 지하철 응용 프로그램의 C#을

코드에서 UserControl XAML에서 사용하고

int eyesState = 1; 

    private void minionAnimation_Tick(object sender, object e) 
    { 
     if (eyesState == -1) 
     { 

      ghosts[0]._bitmapImage.UriSource = new Uri(this.BaseUri, @"Assets/test.png"); 
     } 
     else 
     { 
      ghosts[0]._bitmapImage.UriSource = new Uri(this.BaseUri, @"Assets/test2.png"); 
     } 

     eyesState *= -1; 
    } 
+1

당신이 그것을 _not_ 있는지 확인 했습니까? – Tigran

+0

안녕하세요 @ Tigran, 당신은 "PropertyChanged! = null"을 언급하고 있습니까? 미안하지만, 난 아직도 이러고있어. – fafarifah

+0

내 말은, 실제 값 comiler가 null이 아님을 의미합니다 – Tigran

답변

1

보십시오 :

XAML :

<BitmapImage UriSource="{Binding Path=BitmapImageUri}" /> 

코드 : 타이머에서

private Uri _bitmapImageUri; 
public Uri BitmapImageUri 
{ 
    get { return _bitmapImageUri; } 
    set 
    { 
     if (_bitmapImageUri == value) return; 
     _bitmapImageUri= value; 
     RaisePropertyChanged("BitmapImageUri"); 
    } 
} 

가 :

ghosts[0].BitmapImageUri = new Uri(this.BaseUri, @"Assets/test.png");