【高德地圖API】Pivot控件中加載地圖并禁止Pivot手勢
如題,解決方案,參考【Windows phone應用開發[20]-禁止Pivot手勢】http://www.rzrgm.cn/chenkai/p/3408658.html。
xaml代碼清單
<phone:PhoneApplicationPage
x:Class="PhoneApp2.Samples.MapPage"
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"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot 是包含所有頁面內容的根網格-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel 包含應用程序的名稱和頁標題-->
<StackPanel Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="我的應用程序" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="頁面名稱" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - 在此處放置其他內容-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:Pivot x:Name="pivot1" Grid.Row="1" Title="pivot" >
<phone:PivotItem x:Name="pivot" CacheMode="{x:Null}" Header="item1" >
<Grid x:Name="mapLayer">
</Grid>
</phone:PivotItem>
<phone:PivotItem CacheMode="{x:Null}" Header="item2">
<Grid x:Name="mapLayer2">
<Button Content="button" Margin="116,232,108,132"/>
<TextBlock Text="item2" Margin="150,174,124,244"/>
</Grid>
</phone:PivotItem>
<phone:PivotItem CacheMode="{x:Null}" Header="item2">
<Grid x:Name="mapLayer3">
<Button Content="button" Margin="116,232,152,132"/>
<TextBlock Text="item2" Margin="150,174,124,244"/>
</Grid>
</phone:PivotItem>
</phone:Pivot>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
cs代碼清單
AMap amap;
AMapMarker marker;
//private Point currentPoint;
//private Point oldPoint;
public MapPage()
{
InitializeComponent();
this.mapLayer.Children.Add(amap = new AMap());
Touch.FrameReported += (s, e) =>
{
if (e.GetPrimaryTouchPoint(amap).Action == TouchAction.Up)
{
//this.pivot1.IsLocked = false;
}
};
//amap.ManipulationStarted += (s, e) =>
// {
// this.pivot1.IsLocked = true;
// };
//amap.Loaded += amap_Loaded;
this.Loaded += MapPage_Loaded;
}
void MapPage_Loaded(object sender, RoutedEventArgs e)
{
Events();
}
private void Events()
{
this.pivot.UseOptimizedManipulationRouting = false;
this.pivot.AddHandler(PivotItem.ManipulationStartedEvent, new EventHandler<ManipulationStartedEventArgs>(pivot_ManipulationStarted), true);
this.pivot.AddHandler(PivotItem.ManipulationDeltaEvent, new EventHandler<ManipulationDeltaEventArgs>(pivot_ManipulationCompleted), true);
}
Point startPoint;
private void pivot_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
startPoint = e.ManipulationOrigin;
}
private void pivot_ManipulationCompleted(object sender, ManipulationDeltaEventArgs e)
{
Point endPoint = e.ManipulationOrigin;
if (endPoint.X - startPoint.X >= 0)
{
#region Control Right Side
e.Complete();
e.Handled = true;
#endregion
}
if (endPoint.X - startPoint.X < 0)
{
#region Control Left Side
e.Complete();
e.Handled = true;
#endregion
}
}
}
作者:十一_x
本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。知識共享署名-非商業性使用-相同方式共享 2.5 中國大陸許可協議

浙公網安備 33010602011771號