[英]How can I create an image gallery from a folder in Windows Phone 8 using XAML and C#?
[英]how can I create an image gallery from a list of image URLs?
我可以使用Amazon SimpleDB獲得一堆圖像URL。 我試圖了解將URL綁定到Repeater並創建相冊的最佳方法。 中繼器可能不是最好的數據控件,因此,如果您能想到一種更好的方法,我歡迎您提出建議。
List<string> imgURLS = new List<string>();
String selectExpression = "Select * From Gallery Where Category = 'imgurls'";
SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression);
SelectResponse selectResponse = sdb.Select(selectRequestAction);
if (selectResponse.IsSetSelectResult())
{
SelectResult selectResult = selectResponse.SelectResult;
foreach (Item item in selectResult.Item)
{
Console.WriteLine(" Item");
if (item.IsSetName())
{
imgURLS.Add(item.Value) //the URL of the image
}
}
}
Repeater1.DataSource = imgURLS;
Repeaster1.DataBind();
在此示例中,我只是構建URL的List [string],但我在網上看到的所有示例都使用帶有Eval類型語句的內聯DataBinding SQL類型函數。
在.aspx頁中,我是否需要設置除ItemTemplate以外的任何東西?
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
//How do I direct my DataSource here?
</ItemTemplate>
</asp:Repeater>
您需要在App_Code目錄中的項目中添加兩個類。
一個將包含字符串類的包裝器(我稱為StringWrapper),另一個將包含List類型的方法。 最后一個方法將返回您的imgURLS列表。
public class StringWrapper
{
public string Value
{ get; set; }
public StringWrapper(string s)
{
this.Value = s;
}
public static implicit operator StringWrapper(string s)
{
return new StringWrapper(s);
}
}
public static class Tools
{
public static List<StringWrapper> GetImgUrls()
{
List<StringWrapper> imgURLS = new List<StringWrapper>();
String selectExpression = "Select * From Gallery Where Category = 'imgurls'";
SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression);
SelectResponse selectResponse = sdb.Select(selectRequestAction);
if (selectResponse.IsSetSelectResult())
{
SelectResult selectResult = selectResponse.SelectResult;
foreach (Item item in selectResult.Item)
{
Console.WriteLine(" Item");
if (item.IsSetName())
{
imgURLS.Add(item.Value) //the URL of the image
}
}
}
return imgURLS;
}
}
然后在設計模式下的aspx頁面上,選擇轉發器,然后單擊右上角。 您單擊選擇的數據源,添加新的數據源。 選擇對象(如果需要,可以重命名),然后單擊“確定”。
然后,取消選中該復選框以查看所有可以使用的對象,選擇創建的類的名稱(此處為“工具”)。 您單擊下一步,然后選擇GetImgUrls方法,然后單擊終止。
然后,要使用它,只需在ItemTemplate中調用<%#Eval(“ Value”)%>,例如:
<ItemTemplate>
<img src='<%# Eval("Value") %>' />
</ItemTemplate>
Eval函數查找屬性,並且字符串除了“ Length”屬性外沒有其他屬性。 這就是為什么需要制作一個字符串包裝程序,以便Eval可以調用Value屬性並獲取字符串值的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.