11

I'm trying to bind the DataSource of a MapTileSource to a property on my view model, but I am getting the error REGDB_E_CLASSNOTREG on the Maps:MapTileSource line (underlined in blue is VS editor). I could always use a binding helper to achieve the same effect (I needed to in the 8.0 version of my app) but this seems like it should just...work. Any idea what is wrong?

<Maps:MapControl Style="{Binding Path=MapStyle}" Center="{Binding Path=MapCenter, Mode=TwoWay}" ZoomLevel="{Binding Path=ZoomLevel, Mode=TwoWay}" MapServiceToken="">
    <Maps:MapControl.TileSources>
        <Maps:MapTileSource Layer="BackgroundReplacement" DataSource="{Binding Path=BaseLayerDataSource}" />
    </Maps:MapControl.TileSources>
</Maps:MapControl>

I also tried with just a static data source with the same effect:

<Maps:MapControl Style="{Binding Path=MapStyle}" Center="{Binding Path=MapCenter, Mode=TwoWay}" ZoomLevel="{Binding Path=ZoomLevel, Mode=TwoWay}" MapServiceToken="">
    <Maps:MapControl.TileSources>
        <Maps:MapTileSource Layer="BackgroundReplacement">
            <Maps:MapTileSource.DataSource>
                <Maps:HttpMapTileDataSource UriFormatString="" />
            </Maps:MapTileSource.DataSource>
        </Maps:MapTileSource>
    </Maps:MapControl.TileSources>
</Maps:MapControl>

Edit: I tried the sample code at http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn632728.aspx and it works fine, so it seems obvious that the MapTileSource itself is not unregistered. But that is all codebehind and uses no data binding, so it is not of much use to me.

Edit 2: If I ignore the error and try to deploy the app to the phone emulator, I get this on InitializeComponent() of the view:

An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in HikePoint.exe but was not handled in user code

WinRT information: Cannot deserialize XBF metadata type list as '%1' was not found in namespace '%0'. [Line: 0 Position: 0]

Additional information: The text associated with this error code could not be found.



Cannot deserialize XBF metadata type list as '%1' was not found in namespace '%0'. [Line: 0 Position: 0]

If there is a handler for this exception, the program may be safely continued.
4

2 回答 2

0

我最终放弃了,只是做了一个行为来为我处理绑定。

public class TileSourceBehavior : DependencyObject, IBehavior
{
    public DependencyObject AssociatedObject { get; private set; }

    public void Attach(Windows.UI.Xaml.DependencyObject associatedObject)
    {
        var mapControl = associatedObject as MapControl;

        if (mapControl == null)
            throw new ArgumentException("TileSourceBehavior can be attached only to MapControl");

        AssociatedObject = associatedObject;
    }

    public void Detach() { }

    public static readonly DependencyProperty TileSourceProperty =
        DependencyProperty.Register("TileSource", typeof(MapTileSource), typeof(TileSourceBehavior), new PropertyMetadata(null, OnTileSourcePropertyChanged));

    public MapTileSource TileSource
    {
        get { return GetValue(TileSourceProperty) as MapTileSource; }
        set { SetValue(TileSourceProperty, value); }
    }

    private static void OnTileSourcePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
    {
        var behavior = dependencyObject as TileSourceBehavior;
        var mapControl = behavior.AssociatedObject as MapControl;

        // remove the existing tile source

        var existingTileSource = mapControl.TileSources.FirstOrDefault(t => t.Layer == MapTileLayer.BackgroundReplacement);

        if (existingTileSource != null)
            mapControl.TileSources.Remove(existingTileSource);

        // add the tile source

        behavior.TileSource.Layer = MapTileLayer.BackgroundReplacement;
        mapControl.TileSources.Add(behavior.TileSource);
    }
}

您因此使用它,TileSource您的 ViewModel 上的 MapTileSource 属性在哪里。

<Maps:MapControl>
  <i:Interaction.Behaviors>
    <behaviors:TileSourceBehavior TileSource="{Binding Path=TileSource}" />
  </i:Interaction.Behaviors>
</Maps:MapControl>
于 2014-12-31T23:42:29.127 回答
0

您的项目平台目标是什么?尝试将其更改为 x64。

关于 SO 的类似问题

于 2014-04-11T09:53:12.213 回答