我正在开发 windows phone 8 应用程序。并使用循环选择器功能绑定城市名称列表。
我得到 json 格式的城市名称列表。
现在我需要将结果绑定到循环选择器作为数据源
XAML 代码
<DataTemplate x:Key="NumberTemplate">
<Grid>
<TextBlock
Text="{Binding }"
FontSize="54"
FontFamily="{StaticResource PhoneFontFamilySemiBold}"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</DataTemplate>
<toolkit:LoopingSelector
x:Name="loopselector"
Grid.Column="1"
Margin="12"
Width="128"
ItemSize="128,128"
ItemTemplate="{StaticResource NumberTemplate}">
<toolkit:LoopingSelector.DataSource>
<local:NumbersDataSource Minimum="0" Maximum="50" />
</toolkit:LoopingSelector.DataSource>
</toolkit:LoopingSelector>
客户代码
public void Citybind()
{
try
{
string city_nameurl = "http://xxxxxxx.yyyyyy";
WebClient city_namewc = new WebClient();
city_namewc.DownloadStringAsync(new Uri(city_nameurl), UriKind.Relative);
city_namewc.DownloadStringCompleted += city_namewc_DownloadStringCompleted;
}
catch (Exception ex)
{
}
}
void city_namewc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
var city_name = e.Result;
loopselector.ItemTemplate = city_name; /* Error Cannot convert string to system.windows.dataTemplat*/
}