を継承したクラスのプロパティを依存性結合、私はXAMLの宣言は次のように起動する「GoogleMap.xaml/.csファイル」という名前のWPFのユーザーコントロールを持っています背後にあるコード:WPF:</p> <pre><code><controls:BaseUserControl x:Class="CompanyNamespace.Controls.GoogleMap" </code></pre> <p>:ユーザーコントロールの基本クラス
public partial class GoogleMap : BaseUserControl{
public static readonly DependencyProperty MapCenterProperty =
DependencyProperty.Register("MapCenter", typeof(string), typeof(GoogleMap), new FrameworkPropertyMetadata(string.Empty, OnMapCenterPropertyChanged));
public string MapCenter {
get { return (string)GetValue(MapCenterProperty); }
set { SetValue(MapCenterProperty, value); }
}
private static void OnMapCenterPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e){
GoogleMap control = source as GoogleMap;
control.SetCenter(e.NewValue.ToString());
}
...
}
私はGoogleMap.xamlからプロパティに対処できるようにするための正しい構文は何:
MapCenter="{Binding Location}"
プロパティがBaseUserControlクラスにある場合、GoogleMap.xamlからこのプロパティにのみバインドできます。
更新 GoogleMapViewModel.cs
public class GoogleMapViewModel : ContainerViewModel{
private string location;
[XmlAttribute("location")]
public string Location {
get {
if (string.IsNullOrEmpty(location))
return appContext.DeviceGeolocation.Location();
return ExpressionEvaluator.Evaluate(location);
}
set {
if (location == value)
return;
location = value;
RaisePropertyChanged("Location");
}
}
。あなたの 'DataContext'はどのように見えますか? –
私はカスタムコントロールを作成し、その視覚を 'ControlTemplate'で定義する方が良いと思います。 –
にvmが追加されました – jchristof