私はWP8の開発に不慣れです。私は数週間オンラインコースを受講しており、コースの2番目のタスクは、天気、ニュース、都市に関連する写真を表示するアプリを開発することでした. これまでのところ、表示する必要があるさまざまなコンテンツのコンテナーとして Panorama コントロールを使用して、MVVM パターンに従ってアプリを開発しました。これ以上、私が直面している問題は、Web サービスから取得した xml データを表示することです。
XAML は次のとおりです。
<phone:panorama x:Name="myPanorama"
DataContext = {Binding Source="WeatherViewModel"}>
<PanoramaItem header="MyWeather">
<Textblock x:name="txtCity"
Text = {Binding Weather.City}
</Textblock>
</PanoramaItem>
<panoramaItem header="Config">
<Text x:Name="txtGetCity"/>
<Button x:Name="btnGetCity"
Command={Binding GetWeatherCommand}/>
</panoramaItem>
</phone:panorama>
私のビューモデル:
public class WeaterViewModel : NotificationEnableObject
{
private Weather _currentWeather;
public Weather GetCurrentWeather
{
get
{
if (_currentWeather == null)
_currentWeather = new Weather();
return _currentWeather;
}
set { _currentWeather = value;
OnPropertyChanged("GetCurrentWeather");
}
}
//Constructor ServiceModel serviceModel = new ServiceModel();
public WeatherViewModel()
{
serviceModel.GetWeatherCompleted += (s, a) =>
{
_currentWeather = new Clima();
_currentWeather.City= a.Results[0].City;
_currentWeather.tempC = a.Results[0].tempC;
};
getWeatherCommand = new ActionCommand(null);
}
ActionCommand getWeatherCommand; // ActionCommand derivied from ICommand
public ActionCommand GetWeatherCommand
{
get
{
if (getWeatherCommand!= null)
{
getWeatherCommand = new ActionCommand(() =>
{
//Call the Service who retrieved the data
});
}
return getWeatherCommand;
}
}
}
指定された Weather は、City プロパティを含む public クラスです。IObservableCollention も使用してみましたが、結果は同じです:-(
パノラマ コントロールでわかるように、2 つのセクションがあります。見たい街を書く欄と、Webサービスから得た情報を表示する欄です。
手がかりや助けをいただければ幸いです
よろしく!