我有一個自定義類Awaitable方法(簡化的東西,我已經剝離下來的代碼):在調用屬性訪問[Windows應用商店的應用程序/城域應用]
public class AlbumItem
{
public StorageFile AlbumThumbnail { get; set;}
}
當我結合這一個ListView:
<ListView.ItemTemplate>
<DataTemplate>
<Grid Height="100" Background="#FFabe372">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="{Binding AlbumSource}" Margin="10" Stretch="Uniform"></Image>
<TextBlock Margin="20 5" Grid.Column="1" Style="{StaticResource AlbumListViewItemStyle}" Text="{Binding AlbumDisplayText}"></TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
的Image
的源設置爲AlbumSource
,因爲我已經想實現AlbumSource
爲Get
- 僅屬性:
public class AlbumItem
{
public StorageFile AlbumThumbnail { get; set;}
public BitmapImage AlbumSource
{
get
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(await AlbumThumbnail.OpenReadAsync());
return bmp;
}
}
}
正如預期的那樣,我不能在訪問器方法中使用await
關鍵字,同時我無法將屬性存根聲明爲async
方法。
有人能指出我正確的方向嗎?我稍後可能會嘗試Converter
。謝謝!
謝謝!我明白了,但弗拉維恩的方法解決了我的迫切需求。我會探索你的方法,看看我能在這之後做好準備。 –
+1這是更正確的答案。沒有技術上的理由說'異步'屬性不能存在;這是一個設計決定,因爲「異步屬性」違背了財產的概念。 –
是的,我迄今爲止實現了我的屬性使用這種方法,是的,它不會嗆我的用戶界面!謝謝一堆! –