2011-10-22 2 views
0

ListView 파생 클래스를 사용하여 몇 개의 컨트롤, 가장 중요한 Image 컨트롤 (m_labelIcon)을 포함하는 Panel 파생 클래스를 만드는 사용자 컨트롤을 만듭니다. 내 자원의 PNG 파일 중 하나에 동적으로 컨트롤의 이미지 소스를 설정하고 : 목록보기가 나타날 때Wp7 ListView는 스크롤 할 때까지 이미지를 표시하지 않습니다.

그러나
Uri uri = new Uri("/MyApp;component/Common/Main/res/drawable/some_icon.png"); 
StreamResourceInfo resourceInfo = Application.GetResourceStream(uri); 
BitmapImage bitmapSource = new BitmapImage(); 

bitmapSource.CreateOptions = BitmapCreateOptions.None; 

bitmapSource.SetSource(resourceInfo.Stream); 
m_labelIcon.Source = bitmapSource; 

, 이미지가 모두 누락되었습니다. 목록을 맨 아래로 스크롤 한 다음 맨 위로 이동하면 이미지가 나타납니다. BitmapCreateOptions.None을 지정 했으므로 이미지를 지연시키는 것을 방지해야합니다 (이미지가 리소스가 아닌 웹에 있음).

ImageOpened 이벤트를 사용해 보았지만 작동하지 않습니다.

의견이 있으십니까?

감사합니다, 디버깅 시간 후

+0

[? 헝가리어 표기법 나쁘다 mkay (http://www.joelonsoftware.com/articles/Wrong.html) –

답변

0

돼지, 나는 간단한 해결책을 우연히 발견. 난 아직도 너비 및 수동과 같이 내 사용자 지정 컨트롤의 생성자에서 이미지 컨트롤의 높이 속성을 설정하는 데 필요한

protected override Size MeasureOverride(Size availableSize) 
{ 
    Size panelDesiredSize = new Size(); 

    double height = Math.Max(getIconSizeToUseInPixels(), 
    m_labelName.DesiredSize.Height); 

    panelDesiredSize = new Size(availableSize.Width, height); 

    return panelDesiredSize; 
} 

protected override Size ArrangeOverride(Size finalSize) 
{ 
    double x = 0; 
    double y = 0; 

    m_labelName.Measure(finalSize); 

    double iconWidth = getIconSizeToUseInPixels(); 
    Size iconSize = new Size(iconWidth, iconWidth); 

    double nameWidth = m_labelName.DesiredSize.Width; 
    double nameHeight = m_labelName.DesiredSize.Height; 

    m_labelIcon.Arrange(new Rect(
    new Point(x, y), iconSize)); 

    m_labelName.Arrange(new Rect(
    new Point(iconWidth, y + (finalSize.Height - nameHeight)/2), 
    new Size(nameWidth, nameHeight))); 
    m_labelName.Width = nameWidth; 
    m_labelName.Height = nameHeight; 

    return finalSize; // Returns the final Arranged size 
} 

: : 심지어 내가 그렇게 좋아 한 ArrangeOverride()와 MeasureOverride 함수()를 오버라이드 (override) 된 것처럼

이 문제를 해결 :

m_labelIcon.Width = getIconSizeToUseInPixels(); 
    m_labelIcon.Height = getIconSizeToUseInPixels(); 
관련 문제