如何使用图像和字符串制作 Windows 手机应用程序 LongListSelecter [英] how to make a windows phone app LongListSelecter with Image and strings
问题描述
我制作了一个简单的长列表选择器应用程序,没有跳转标题或标题模板.我在谷歌和堆栈溢出的长途旅行后做到了.我很满意.该应用程序仅包含用于显示姓名的文本块 - 例如名字姓氏电话号码,但我需要添加照片以及如何显示图片和姓名的代码.我搜索了很多都找不到合适的解决方案,这是我的代码:
i made a simple long list selector app without jump header or header template. i made it after a long journey in to the google and stack overflow. i was satisfied with it. the app contains only text blocks to show names- like first name last name phone number but i need to add photos also what would be the code how to show pictures along with names. i search a lot couldn't get a proper solution here is my code:
namespace listparee6
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
List<SpeedDial> speeddial = new List<SpeedDial>();
speeddial.Add(new SpeedDial ( "deepu", "43" ));
speeddial.Add(new SpeedDial ( "anoop","32" ));
speeddial.Add(new SpeedDial ( "abhilash","76" ));
SpeedDialLLS.ItemsSource = speeddial;
}
public class SpeedDial
{
public string Name { get; set;}
public String Phone { get; set; }
public SpeedDial(string peru, string num)
{this.Phone=num ;
this.Name = peru;
}
}
}
}
推荐答案
我找到了一个更好的方法.
I found a better way to do that.
项目主要需要3个组件.
Project needs 3 components mainly.
- xml 文件
- xml.cs 文件
- 类文件
含义主要在这些文件中.
Implications are mainly made in these file.
在 XML 文件中排列所有控件拖放 longlistselector 控件
In XML file arrange all control drag and drop longlistselector control
<phone:LongListSelector x:Name="LLs" HorizontalAlignment="Left" Height="566" VerticalAlignment="Top" Width="401" Margin="42,144,0,0">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel>
<Image Source="{Binding Photo}" Height="100" Width="100" HorizontalAlignment="Left"/>
<TextBlock Text="{Binding Names}" HorizontalAlignment="Right"/>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
xml.cs
public partial class MainPage : PhoneApplicationPage
{
ObservableCollection<SpeedDial> speedDialList = new ObservableCollection<SpeedDial>();
// Constructor
public MainPage()
{
InitializeComponent();
speedDialList = new ObservableCollection <SpeedDial>();
speedDialList.Add(new SpeedDial() { Names = "deepu", Photo = new Uri("Image/2.jpg",UriKind.Relative) });
speedDialList.Add(new SpeedDial() { Names = "jilu", Photo = new Uri("Image/3.jpg",UriKind.Relative) });
speedDialList.Add(new SpeedDial() { Names = "tinu", Photo = new Uri("Image/4.jpg",UriKind.Relative) });
speedDialList.Add(new SpeedDial() { Names = "jhd", Photo = new Uri("Image/7.jpg",UriKind.Relative) });
speedDialList.Add(new SpeedDial() { Names = "jose", Photo = new Uri("image/1.jpg",UriKind.Relative) });
speedDialList.Add(new SpeedDial() { Names = "hgscf", Photo = new Uri("image/2.jpg",UriKind.Relative) });
speedDialList.Add(new SpeedDial() { Names = "hjsg", Photo = new Uri("Image/5.jpg",UriKind.Relative) });
speedDialList.Add(new SpeedDial() { Names = "jhvdj", Photo = new Uri("Image/6.jpg" ,UriKind.Relative) });
speedDialList.Add(new SpeedDial() { Names = "jhd", Photo = new Uri("Image/7.jpg",UriKind.Relative) });
speedDialList.Add(new SpeedDial() { Names = "jkgh", Photo = new Uri("Image/4.jpg",UriKind.Relative) });
speedDialList.Add(new SpeedDial() { Names = "kigh", Photo = new Uri("Image/3.jpg",UriKind.Relative) });
LLs.ItemsSource = speedDialList;
}
}
}}
类文件
namespace yourprojuctname
{
class SpeedDial
{
public string name;
public string Names
{
get { return name; }
set { name = value; }
}
private Uri photo;
public Uri Icon
{
get { return photo; }
set { photo = value; }
}
}
}
这篇关于如何使用图像和字符串制作 Windows 手机应用程序 LongListSelecter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!