我正在使用Windows Phone 7應用程序在運行時下載幾個圖像(這意味着它們不會作爲資源添加到我的可執行文件中)。如何將我下載的圖像設置爲我的列表框UI對象?
對於下載圖像,我使用下一個鏈接描述的方法: Set image source to an uri 它似乎工作正常。
我很難嘗試將我的下載圖像設置到包含自定義控件的列表框中。
在我的XAML頁面我lisbox看起來是這樣的:
<ListBox x:Name="listBox_1" Margin="0,0,-12,0" ItemsSource="{Binding Items}">
<ListBox.ItemTemplate>
<DataTemplate>
<mylocal:customcontrol_A id="{Binding PId}" />
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
我的自定義控件包含一個圖像和幾個TextBlock中的如下:
<Grid x:Name="LayoutRoot" Height="180" Width="470" Margin="0,10,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="452*" />
<ColumnDefinition Width="18*" />
</Grid.ColumnDefinitions>
<Image Name="img_1" Source="{Binding PImage1, Converter={StaticResource requestConverter}}" />
<TextBlock Name="txtB_0" Text="{Binding PName0}" Foreground="Black" />
<TextBlock Name="txtB_1" Text="{Binding PName1}" Foreground="Black" />
</Grid>
即時通訊使用的轉換器來啓動Web客戶端即會下載圖像。
一旦我的異步請求完成,並且我的圖像存儲在我的IsolatedStorageFile區域中,我可以在我的MainPage的回調函數上構建一個BitMapImage,但是我還沒有找到如何迭代我的listBox_1以訪問我的自定義命令圖像設置Source屬性如上面的鏈接建議。
我想做點什麼相當於未來
BitmapImage image = new BitmapImage();
image.SetSource(stream);
foreach (customcontrol_A bc in listBox_1.Items)
{
if (bc.id == id)
{
bc.img_1.Source = image;
founded = true;
break;
}
}
但問題是,listBox_1.Items是myBindingClassA的實例,而不是實際的GUI元素customcontrol_A。
我真的很感激任何關於如何獲得對圖像GUI對象的引用的建議,所以我可以簡單地使用BitmapImage設置源。
非常感謝!
我回答之前的一個簡單問題,爲什麼您需要將它存儲在本地?你知道一個事實,圖像永遠不會改變嗎? –
嗨肖恩,是的,它不會改變,我在本地需要它的情況下,應用程序在沒有連接的地區使用,也只做一次,並保存數據消費用戶。 – Alx