2014-04-07 10 views
11

Ich versuche, die DataSource einer MapTileSource an eine Eigenschaft in meinem Ansichtsmodell zu binden, aber ich erhalte den Fehler REGDB_E_CLASSNOTREG in der Maps: MapTileSource-Zeile (blau unterstrichen ist VS-Editor) . Ich könnte immer einen Binding-Helfer verwenden, um den gleichen Effekt zu erzielen (ich musste in der Version 8.0 meiner App), aber das scheint so, als müsste es einfach ... funktionieren. Irgendeine Idee was falsch ist?Windows Phone 8.1 MapTileSource-Bindung mit MVVM

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

ich auch mit nur einem statischen Datenquelle versucht, mit der gleichen Wirkung:

<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: Ich habe versucht, den Beispielcode in http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn632728.aspx und es funktioniert gut, so scheint es offensichtlich, dass die MapTileSource selbst ist nicht nicht registriert. Aber das ist alles Codebehind und verwendet keine Datenbindung, also ist es für mich nicht von großem Nutzen.

Edit 2: Wenn ich den Fehler ignorieren und versuchen, die App auf dem Handy-Emulator zu implementieren, erhalte ich diese auf InitializeComponent() der Ansicht:

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. 
+0

Ich vermute, Sie haben keine Lösung gefunden? –

+0

Nein, ich habe stattdessen einen Bindungshelfer verwendet, da ich ihn nicht in beide Richtungen brauche. Ich kann den Code veröffentlichen, wenn Sie wollen, wenn ich nach Hause komme. –

+2

Ich würde mich freuen zu sehen, wie Sie diesen Fehler umgangen haben. Ich bekomme den gleichen Fehler, wenn ich versuche, ein Quell-MediaCapture an ein CaptureElement zu binden. –

Antwort

0

ich schließlich aufgegeben und machte nur ein Verhalten für mich die Bindung zu handhaben.

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

Sie es so zu verwenden, wo TileSource ein MapTileSource Eigentum auf Ihrem Viewmodel ist.

<Maps:MapControl> 
    <i:Interaction.Behaviors> 
    <behaviors:TileSourceBehavior TileSource="{Binding Path=TileSource}" /> 
    </i:Interaction.Behaviors> 
</Maps:MapControl> 
0

Was ist Ihr Projektplattform Ziel ist? Versuchen Sie, es in x64 zu ändern.

Similar Question on SO

+0

Es ist eine Windows Phone App; x64 ist kein gültiges Build-Ziel. –

+0

ja Entschuldigung, ich werde es nach der Arbeit versuchen –