我是 Windows 手机应用程序开发的新手。我制作了一个应用程序,我使用 Web 客户端向 MySQL 中的数据库请求数据。我从该请求中得到响应,但问题是我使用带有项目模板和数据模板的列表框在列表框中绑定响应数据。当我更改传递给 Web 客户端的 URL 时,它无法在列表框中绑定数据。即使只是文本块的文本也不会显示。但是当我从中删除数据模板和项目模板时列表框将显示静态数据但不显示绑定数据。请任何人帮助我...
在此先感谢。我希望有人能尽快帮助我...我的 C# 代码是:
public partial class chat_match_settings : PhoneApplicationPage
{
public chat_match_settings()
{
InitializeComponent();
Loaded += new RoutedEventHandler(profile_loaded);
}
void profile_loaded(object sender, RoutedEventArgs e)
{
WebClient wc = new WebClient();
var URI = new Uri("<http://www.mylocalipaddress.com/eyematch/rest1-7/api/>?");
wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";
wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);
wc.UploadStringAsync(URI, "POST", "action=login&uName=hiren&uPass=hiren123");
}
private void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
try
{
var jsondata = JsonConvert.DeserializeObject<RootObject>(e.Result);
DisplayList list = new DisplayList(jsondata.profile.DisplayData);
//profilelistview.DataContext = this;
profilelistview.ItemsSource = list;
}
catch (Exception exc)
{}
}
public class DisplayList : List<DisplayData>
{
public DisplayList(DisplayData data)
{
Add(new DisplayData
{
Username = data.FullName.ToString(),
countryname = data.countryname.ToString(),
Sex = data.Sex.ToString(),
City = data.City.ToString(),
AboutMyself = data.AboutMyself.ToString(),
Job = data.Job.ToString(),
Location = data.Location.ToString(),
MatchSex = data.MatchSex.ToString(),
Iam = data.Iam.ToString(),
StartWorkHour = data.StartWorkHour.ToString(),
Age = data.Age,
EndWorkHour = data.EndWorkHour.ToString(),
Language = data.Language,
MessageMe = data.MessageMe.ToString(),
Ilove = data.Ilove.ToString(),
LookingFor = data.LookingFor.ToString(),
BodyDescription = data.BodyDescription });
}
}
public class DisplayList1 : List<ProfileImage>
{
public DisplayList1(ProfileImage profileImage)
{
// TODO: Complete member initialization
Add(new ProfileImage
{ Value = "<http://localipaddress.com/eyematch/upload/images/2/>?" + profileImage.Value });
}
和xml代码是:
<Image x:Name="matchimage"/><TextBlock x:Name="matchpercentage"/>
<TextBlock Text="{Binding Path=UserFeedBackForDisplay}"></TextBlock>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path= Sex}" Foreground="Gray" FontSize="16" Margin="0"/>
<TextBlock Text="/" FontSize="16"/>
<TextBlock Text="{Binding Path=Sex}" Foreground="Gray" FontSize="16"></TextBlock>
<TextBlock Text="/" FontSize="16"/>
<TextBlock Text="{Binding Path=Job}" Foreground="Gray" FontSize="16"></TextBlock>
<TextBlock Text="/" FontSize="16"/>
<!--<ListBox Name="language" Foreground="Gray" FontSize="16">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=contactdata.Title}" Foreground="Gray" FontSize="16"></TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>-->
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<TextBlock Text="{Binding Path=City}" Foreground="Gray" FontSize="16"></TextBlock>
<TextBlock Text="/" FontSize="16"/>
<TextBlock Text="{Binding Path=countryname}" Foreground="Gray" FontSize="16"></TextBlock>
</StackPanel>
<StackPanel Margin="0,10,0,0">
</StackPanel>
<StackPanel Orientation="Vertical" Margin="0,10,0,0">
<TextBlock Text="About MySelf" FontSize="30" ></TextBlock>
<TextBlock Text="{Binding Path=AboutMyself}" Foreground="Gray" Height="60" Width="Auto" TextWrapping="Wrap" FontSize="16"></TextBlock>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="0,10,0,0">
<TextBlock Text="I Am" FontSize="30" ></TextBlock>
<StackPanel Orientation="Horizontal">
<TextBlock Text="I 'm " Foreground="Gray" FontSize="16" />
<TextBlock Text="{Binding Path=BodyDescription.BodyStyle}" Foreground="Gray" Width="Auto" TextWrapping="Wrap" FontSize="16"></TextBlock>
<TextBlock Text="/" FontSize="16"/>
<TextBlock Text="{Binding Path=BodyDescription.Hair}" Foreground="Gray" Width="Auto" TextWrapping="Wrap" FontSize="16"></TextBlock>
<TextBlock Text=" Hair " Foreground="Gray" FontSize="16" />
<TextBlock Text="/" FontSize="16"/>
<TextBlock Text="{Binding Path=BodyDescription.Eyes}" Foreground="Gray" FontSize="16"></TextBlock>
<TextBlock Text=" Eyes " Foreground="Gray" FontSize="16" />
</StackPanel>
<TextBlock Text="{Binding Path=Iam}" Foreground="Gray" FontSize="16"></TextBlock>
</StackPanel>
<StackPanel Margin="0,10,0,0">
<TextBlock Text="I Love" FontSize="30"></TextBlock>
<TextBlock Text="{Binding Path=Ilove}" Foreground="Gray" FontSize="16"></TextBlock>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="0,10,0,0">
<TextBlock Text="I'm Looking For" FontSize="26"></TextBlock>
<TextBlock Text="{Binding Path=LookingFor}" Foreground="Gray" FontSize="16"></TextBlock>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="0,10,0,0">
<TextBlock Text="Message Me" FontSize="30"></TextBlock>
<TextBlock Text="{Binding Path=MessageMe}" Foreground="Gray" FontSize="16"></TextBlock>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="0,10,0,0">
<TextBlock Text="Match Sex" FontSize="30" ></TextBlock>
<TextBlock Text="{Binding Path=MatchSex}" Foreground="Gray" FontSize="16"></TextBlock>
</StackPanel >
<StackPanel Orientation="Vertical" Margin="0,10,0,0">
<TextBlock Text="Start Working Hour" FontSize="30" ></TextBlock>
<TextBlock Text="{Binding Path=StartWorkHour}" Foreground="Gray" FontSize="16" ></TextBlock>
</StackPanel>
<StackPanel Margin="0,10,0,0">
<TextBlock Text="End Working Hour" FontSize="30" ></TextBlock>
<TextBlock Text="{Binding Path=EndWorkHour}" Foreground="Gray" FontSize="16"></TextBlock>
</StackPanel>
<TextBlock Text="{Binding Username}" FontSize="16"></TextBlock>
<TextBlock Text="{Binding Path=Location}" Foreground="Gray" FontSize="16"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>