【发布时间】:2011-11-05 14:51:57
【问题描述】:
我正在使用地图控件为 windows phone 开发应用程序。地图控件将其中心和缩放级别属性绑定到视图模型上的两个属性。
地图控件位于与应用程序主页分开的页面上。每次用户移动到地图时,页面都会绑定到视图模型。这个视图模型是一个单例(总是相同的实例)。
我第一次移动到地图时在地图上导航工作正常,但是当我返回并再次导航到地图时,导航会出现某种反弹,就像它被推回其初始位置一样。 要查看此行为,请执行以下操作:
- 单击主页上的按钮导航到 mapPage bij。此时地图控件按预期工作。
- 点击返回按钮返回主页。
- 再次单击主页上的按钮以第二次导航到地图页面。现在,当滑动地图时,控件的行为很奇怪,会在滑动前弹回原来的位置。
主页只包含一个导航到地图页面的按钮,如下所示:
<phone:PhoneApplicationPage
x:Class="MapTester.Map"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:maps="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True"
DataContext="{Binding Path=MapViewModel, Source={StaticResource ViewModelLocator}}">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<maps:Map Center="{Binding Center, Mode=TwoWay}"
ZoomLevel="{Binding ZoomLevel,Mode=TwoWay}"
ZoomBarVisibility="Visible"
CredentialsProvider=""
ScaleVisibility="Visible"></maps:Map>
</Grid>
</phone:PhoneApplicationPage>
MapViewModel 是在 ViewModelLocator 上定义的。我创建了一个解决方案来演示当时的问题。你可以在这里下载它https://skydrive.live.com/?cid=25374d9051083633&sc=documents&id=25374D9051083633%21344#
有人知道如何解决这个问题吗?
谢谢!
【问题讨论】:
-
我也有同样的问题,JLaanstra 找到解决方法了吗?
-
所以我相信我所做的就是在导航离开时删除绑定。
标签: c# data-binding windows-phone-7 mvvm bing-maps