我是新來的Silverlight,我試圖使用數據綁定。 這看起來簡單,但它不工作,我找不到爲什麼...數據綁定不起作用,出了什麼問題? Silverlight WP7
在我MainPage.xaml中
<map:Map Name="bing_map" Height="578" Width="480"
ZoomLevel="{Binding ZoomLevel, Mode=TwoWay}"
Center="{Binding Center, Mode=TwoWay}"
CredentialsProvider="{StaticResource BingMapsKey}" />
正如你所看到的,我試圖在縮放級別和綁定中央。
在我MainPage.xaml.cs中
從類繼承INotifyPropertyChanged的
在構造函數中:
ZoomLevel = 12.0;
Center = new GeoCoordinate(0, 0);
性能:
private double _zoom_level;
private double ZoomLevel
{
get { return _zoom_level; }
set {
if (_zoom_level == value) return;
_zoom_level = value;
RaisePropertyChanged("ZoomLevel");}
}
private GeoCoordinate _center;
private GeoCoordinate Center
{
get { return _center; }
set {
if (_center == value) return;
_center = value;
RaisePropertyChanged("Center"); }
}
public event PropertyChangedEventHandler PropertyChanged;
void RaisePropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
我忘了什麼?
我已經被困在這3小時開始是一個簡單的綁定一段時間...
預先感謝您的幫助! :)
嗯,我希望這麼辛苦,這是去上班......但是事與願違:/還是要謝謝你。 –
@尼克勞斯:雷是正確的,你也應該設置Datacontext。建議使用MVVM模式。我也編輯了答案。 – MichaelS
非常感謝!我在某處讀到數據上下文自動設置爲根目錄...但它看起來像是一個謊言(如蛋糕)。 –