Bing Maps WPF in the MVVM template. Center not working?

Hello Stackoverflow Community! I started recently creating a flight control panel, including Bing Maps WPF Control in MVVM patters (at least as much as possible) for PC with PC.

After searching the Internet for some time, I was able to deliver the CredentialsProvider based on the key in app.config and switched to automatically centering the Bing control card based on the current position of the device.

XAML:

<m:Map ZoomLevel="16" Mode="Aerial" CredentialsProvider="{Binding BingMapsCredentials}" Grid.Row="1" Grid.ColumnSpan="2" Center="{Binding DevPosition}"/>

ViewModel:

    private readonly CredentialsProvider bingMapsCredentials = new ApplicationIdCredentialsProvider(ConfigurationSettings.AppSettings.Get("BingMapsKey"));
    private readonly double nDefaultLatitude = double.Parse(ConfigurationSettings.AppSettings.Get("DefaultLongitude"), System.Globalization.CultureInfo.InvariantCulture);
    private readonly double nDefaultLongitude = double.Parse(ConfigurationSettings.AppSettings.Get("DefaultLatitude"), System.Globalization.CultureInfo.InvariantCulture);
    private GeoCoordinate nDevicePosition;

    public CredentialsProvider BingMapsCredentials
    {
        get { return bingMapsCredentials; }
    }
    public Location DevPosition
    {
        get { return new Location(nDeviceLat, nDeviceLon); }
    }
    public double nDeviceLon
    {
        get
        {
            if (nDevicePosition.IsUnknown)
                return nDefaultLongitude;
            else
                return nDevicePosition.Longitude; }
        set { nDevicePosition.Longitude = value; }
    }
    public double nDeviceLat
    {
        get
        {
            if (nDevicePosition.IsUnknown)
                return nDefaultLatitude;
            else
                return nDevicePosition.Latitude;
        }
        set { nDevicePosition.Latitude = value; }
    }

When binding, CredentialsProvider works fine, setting the center location is completely absent. The map is displayed correctly, but somewhere in the middle of nowhere. The debugger indicates that there is no call to the Get property in the location. There are also no WPF warning / error traces in the output window.

Am I missing something?

Any help is appreciated.

R.

+4
2

nDeviceLat nDeviceLon DevPosition. , get . , , . - :

public Location DevPosition { get; set; }

public double nDeviceLon
{
    get
    {
        if (nDevicePosition.IsUnknown)
            return nDefaultLongitude;
        else
            return nDevicePosition.Longitude; }
    set 
{ 
    nDevicePosition.Longitude = value; 
    DevPosition = new Location(nDeviceLat, nDeviceLon);
}
}
public double nDeviceLat
{
    get
    {
        if (nDevicePosition.IsUnknown)
            return nDefaultLatitude;
        else
            return nDevicePosition.Latitude;
    }
    set { 
    nDevicePosition.Latitude = value; 
    DevPosition = new Location(nDeviceLat, nDeviceLon);
}
}
0

Source: https://habr.com/ru/post/1533547/


All Articles