【高德地图API】Pivot控件中加载地图并禁止Pivot手势
如题,解决方案,参考【Windows phone应用开发[20]-禁止Pivot手势】http://www.cnblogs.com/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 中国大陆许可协议