c# - Bing 在 MVVM 模式中映射 WPF。中心不工作?

标签 c# wpf mvvm maps bing-maps

你好 Stackoverflow 社区! 我最近开始构建飞行仪表板,包括用于 Windows PC 设备的 MVVM 模式中的 Bing Maps WPF 控件(至少尽可能多)。

在网上搜索了一段时间后,我能够根据 app.config 中的 key 提供 CredentialsProvider,并开始根据当前设备的位置实现 Bing 控制图的自动居中。

XAML:

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

View 模型:

    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; }
    }

虽然绑定(bind) CredentialsProvider 工作正常,但设置中心位置根本不起作用。 map 显示正确,但在某个偏僻的地方。调试器显示没有调用位置上的 Get 属性。输出窗口中也没有 WPF 警告/错误跟踪。

我是不是漏掉了什么?

感谢任何帮助。

P.

最佳答案

您还没有将 nDeviceLat 和 nDeviceLon 绑定(bind)到 DevPosition。因此,这只会在调用 get 方法时引入正确的值。如果移动位置,则不会触发 UI 更新。尝试做这样的事情:

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);
}
}

关于c# - Bing 在 MVVM 模式中映射 WPF。中心不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22663483/

相关文章:

c# - 使用NuGet软件包管理器控制台为C#安装EMGU OpenCV

c# - 在 ListView WPF 中设置项目焦点

mvvm - 来自 iNotifyPropertyChanged 系统的 View 模型之间的通信

c# - 将 CheckBox IsChecked 属性绑定(bind)到 ListView 的 SelectedItems 属性

C#/Java - 从 Android 模拟器使用 WCF 服务

c# - WPF MVVM-简单登录到应用程序

c# - 为什么使用 Google Cloud Firestore 1.0.0-beta05 C# SetAsync 时会出现 Grpc.Core.RpcException StatusCode=Unavailable, Detail ="Connect Failed"?

c# - 如何覆盖 DataGrid 选择行为?

WPF 字体 : Why are some characters missing?

wpf - 在 MVVM 中显示有关集合项的补充信息