I have a user control in wpf named "GoogleMap.xaml/.cs" where the xaml declaration starts like this:
<controls:BaseUserControl x:Class="CompanyNamespace.Controls.GoogleMap" the code behind:
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()); } ... } What's the correct syntax for me to be able to address the property from GoogleMap.xaml:
MapCenter="{Binding Location}" I can only bind to this property from GoogleMap.xaml if I place the property is in the BaseUserControl class.
Update 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"); } }
DataContextlook like?ControlTemplate.