2012-12-10 52 views
0

我做了這個Windows Phone的用戶控件:複選框列表與圖像

enter image description here

XAML:

<Grid x:Name="LayoutRoot" Height="75" Width="353"> 
     <Image Height="50" HorizontalAlignment="Left" Margin="12,12,0,0" Name="img" Stretch="Fill" VerticalAlignment="Top" Width="50" /> 
     <TextBlock Height="50" HorizontalAlignment="Left" Margin="77,12,0,0" Name="txt" Text="TextBlock" VerticalAlignment="Top" Width="215" FontSize="32" /> 
     <CheckBox Content="CheckBox" Height="68" HorizontalAlignment="Right" Margin="0,3,10,0" Name="cb" VerticalAlignment="Top" Width="50" /> 
</Grid> 

而且我在網頁的一個稱呼它是

XAML.CS:

myListBox mls = new myListBox(); 
String[,] ls = { { "Text1", "/image/image1.png" }, { "Tex2", "/image/image2.png" } }; 
for (int i = 0; i < 2; i++) 
{ 
     mls.txt.Text = ls[i, 0]; 
     mls.img.Source = url(ls[i, 1]); 
} 

public ImageSource url (string path) 
{ 
     Uri uri = new Uri(path, UriKind.Absolute); 
     ImageSource imgSource = new BitmapImage(uri); 
     return imgSource; 
} 

我的問題是:

1)如果我跑這就像把它帶到下面的代碼,但如果我改變for循環i<1它工作正常(但不正是我期待看問題2)

// Code to execute on Unhandled Exceptions 
    private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) 
    { 
     if (System.Diagnostics.Debugger.IsAttached) 
     { 
      // An unhandled exception has occurred; break into the debugger 
      System.Diagnostics.Debugger.Break(); 
     } 
    } 

2)使用此代碼我設置文本和圖像,但它沒有放置圖像,只有文本。

+0

@ weberc2如果你要編輯標題請做好它不要只刪除標籤 –

+0

我只是想出了第一個問題......我需要把'myListBox mls = new myListBox();'在循環內..現在我唯一的問題是第二部分.. – a1204773

+0

@ConradFrix這在我過去提出的問題上很常見 - 我繼續傳統。請指導我發表一些關於此事的裁決,我會很樂意改變。現在,我正在做社區似乎想要的。 – weberc2

回答

1

我有一個類似的工作代碼,我已經使用UriKind「相對」,而不是「絕對」

還有一件事。確保您正在使用的圖片屬性下的「構建動作」設置爲「內容」而非「資源」或其他任何內容。

希望它能起作用。