以前想要禁止内置的手势动作,看了一下网上是设置 IsLocked="True".

但是拿到UWP上来,靠,设置了之后header只显示当前的那个header。这样的设计真是丑爆了。。没办法,只能自己研究。看了看Pivot的模板,找到个方法。

不多说。直接上代码。

        <Pivot ><PivotItem Header="Header1"><Grid ManipulationMode="TranslateX" PointerPressed="Grid_PointerPressed" PointerReleased="Grid_PointerReleased"></Grid></PivotItem><PivotItem Header="Header2"></PivotItem><PivotItem Header="Header3"></PivotItem></Pivot>

比如说我想在第一个item里面做一些拖拽的动作,因为有内置手势,没法直接使用。
为Grid增加上面的事件和属性设置,注意

ManipulationMode="TranslateX" 是必然设置的,根据你自己的需求。

再看一下后台的代码

        Pivot pivot = null;private void Grid_PointerPressed(object sender, PointerRoutedEventArgs e){if (pivot == null){var parent = (sender as Grid).Parent as FrameworkElement;while (parent != null){pivot = parent as Pivot;if (pivot != null){ScrollViewer.SetHorizontalScrollMode(pivot, ScrollMode.Disabled);break;}parent = parent.Parent as FrameworkElement;}}else{ScrollViewer.SetHorizontalScrollMode(pivot, ScrollMode.Disabled);}}private void Grid_PointerReleased(object sender, PointerRoutedEventArgs e){if (pivot != null){ScrollViewer.SetHorizontalScrollMode(pivot, ScrollMode.Enabled);}}

控制ScrollViewer的HorizontalScrollMode 属性。。我上面写成这样是因为,项目里面不是简单的grid,是一个自定义的页面。反正意思就是去拿到Pivot,进行设置就ok了。

有更好的办法的同学分享一下。

又查看了一下模板,修改了模板之后还是可以继续使用IsLocked 属性。注意蓝色部分,将它注释掉就可以了

<Style TargetType="PivotHeaderItem">
<Setter Property="FontSize" Value="{ThemeResource PivotHeaderItemFontSize}" />
<Setter Property="FontFamily" Value="{ThemeResource PivotHeaderItemFontFamily}" />
<Setter Property="FontWeight" Value="{ThemeResource PivotHeaderItemThemeFontWeight}" />
<Setter Property="CharacterSpacing" Value="{ThemeResource PivotHeaderItemCharacterSpacing}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
<Setter Property="Padding" Value="{ThemeResource PivotHeaderItemMargin}" />
<Setter Property="Height" Value="48" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template"><Setter.Value><ControlTemplate TargetType="PivotHeaderItem"><Gridx:Name="Grid"Background="{TemplateBinding Background}"><Grid.Resources><Style x:Key="BaseContentPresenterStyle" TargetType="ContentPresenter"><Setter Property="FontFamily" Value="XamlAutoFontFamily"/><Setter Property="FontWeight" Value="SemiBold"/><Setter Property="FontSize" Value="15"/><Setter Property="TextWrapping" Value="Wrap"/><Setter Property="LineStackingStrategy" Value="MaxHeight"/><Setter Property="TextLineBounds" Value="Full"/><Setter Property="OpticalMarginAlignment" Value="TrimSideBearings"/></Style><Style x:Key="BodyContentPresenterStyle" TargetType="ContentPresenter" BasedOn="{StaticResource BaseContentPresenterStyle}"><Setter Property="FontFamily" Value="{ThemeResource PivotHeaderItemFontFamily}" /><Setter Property="FontWeight" Value="{ThemeResource PivotHeaderItemThemeFontWeight}"/><Setter Property="FontSize" Value="{ThemeResource PivotHeaderItemFontSize}"/></Style></Grid.Resources><VisualStateManager.VisualStateGroups><VisualStateGroup x:Name="SelectionStates"><VisualStateGroup.Transitions><VisualTransition From="Unselected" To="UnselectedLocked" GeneratedDuration="0:0:0.33" /><VisualTransition From="UnselectedLocked" To="Unselected" GeneratedDuration="0:0:0.33" /></VisualStateGroup.Transitions><VisualState x:Name="Disabled"><Storyboard><ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"Storyboard.TargetProperty="Foreground" ><DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseMediumLowBrush}" /></ObjectAnimationUsingKeyFrames></Storyboard></VisualState><VisualState x:Name="Unselected" /> <VisualState x:Name="UnselectedLocked"><Storyboard><DoubleAnimation Storyboard.TargetName="ContentPresenterTranslateTransform"Storyboard.TargetProperty="X"Duration="0" To="{ThemeResource PivotHeaderItemLockedTranslation}" /><DoubleAnimation Storyboard.TargetName="ContentPresenter"Storyboard.TargetProperty="(UIElement.Opacity)"Duration="0" To="0" /></Storyboard></VisualState><VisualState x:Name="Selected"><Storyboard><ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"Storyboard.TargetProperty="Foreground" ><DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" /></ObjectAnimationUsingKeyFrames><ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid"Storyboard.TargetProperty="Background" ><DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" /></ObjectAnimationUsingKeyFrames></Storyboard></VisualState><VisualState x:Name="UnselectedPointerOver"><Storyboard><ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"Storyboard.TargetProperty="Foreground" ><DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseMediumHighBrush}" /></ObjectAnimationUsingKeyFrames><ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid"Storyboard.TargetProperty="Background" ><DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" /></ObjectAnimationUsingKeyFrames></Storyboard></VisualState><VisualState x:Name="SelectedPointerOver"><Storyboard><ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"Storyboard.TargetProperty="Foreground" ><DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseMediumHighBrush}" /></ObjectAnimationUsingKeyFrames><ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid"Storyboard.TargetProperty="Background" ><DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" /></ObjectAnimationUsingKeyFrames></Storyboard></VisualState><VisualState x:Name="UnselectedPressed"><Storyboard><ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"Storyboard.TargetProperty="Foreground" ><DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseMediumHighBrush}" /></ObjectAnimationUsingKeyFrames><ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid"Storyboard.TargetProperty="Background" ><DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" /></ObjectAnimationUsingKeyFrames></Storyboard></VisualState><VisualState x:Name="SelectedPressed"><Storyboard><ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"Storyboard.TargetProperty="Foreground" ><DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseMediumHighBrush}" /></ObjectAnimationUsingKeyFrames><ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid"Storyboard.TargetProperty="Background" ><DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" /></ObjectAnimationUsingKeyFrames></Storyboard></VisualState></VisualStateGroup></VisualStateManager.VisualStateGroups><ContentPresenterx:Name="ContentPresenter"Content="{TemplateBinding Content}"ContentTemplate="{TemplateBinding ContentTemplate}"Margin="{TemplateBinding Padding}"FontSize="{TemplateBinding FontSize}"FontFamily="{TemplateBinding FontFamily}"FontWeight="{TemplateBinding FontWeight}"HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"VerticalAlignment="{TemplateBinding VerticalContentAlignment}"><ContentPresenter.RenderTransform><TranslateTransform x:Name="ContentPresenterTranslateTransform" /></ContentPresenter.RenderTransform></ContentPresenter></Grid></ControlTemplate></Setter.Value>
</Setter>
</Style>

转载于:https://www.cnblogs.com/FaDeKongJian/p/5309974.html

UWP 禁止Pivot swip 手势相关推荐

  1. Android高德地图如何禁止地图在拖动时发生旋转.

    代码: aMap.getUiSettings().setRotateGesturesEnabled(false);//禁止地图旋转手势. aMap.getUiSettings().setTiltGes ...

  2. 2018-8-10-dotnet-从入门到放弃的-500-篇文章合集

    title author date CreateTime categories dotnet 从入门到放弃的 500 篇文章合集 lindexi 2018-08-10 19:16:52 +0800 2 ...

  3. dotnet 从入门到放弃的 500 篇文章合集

    本文是记录我从入门到放弃写的博客 博客包括 C#.WPF.UWP.dotnet core .git 和 VisualStudio 和一些算法,所有博客使用 docx 保存 下载:dotnet 从入门到 ...

  4. audio 上一首 下一首 自定义样式_被 iPhone 吹爆的最香功能,安卓也终于安排上了...

    大家好,我是今天找到又一快乐根源的酷玩君. 其实,想获取快乐的方式很简单,就是克服困难取得新的成就 新的技巧 . iOS 14中,这个双击后盖有惊喜的场面,大家都见过了吧? 通过敲击两下或三下手机背部 ...

  5. cahrt框架 ios_iOS - Charts(一) - BarChartView

    platform:ios,'10.0' inhibit_all_warnings! use_frameworks! target 'iOS_Charts' do pod 'Charts' #pod ' ...

  6. [06.21] LinkLabel 代码重构和我的SinaWeibo7 Project Todolist

    前些天发过一个LinkLabel的文章,这些天我用过之后发现很多不方便的地方,前两天着手改进了一下. 给link类添加一个属性叫type,目的是为了给不同类型例如 @xxx #xxx# 和 http: ...

  7. 如何冥想?2500年的智慧——荒岛十日记

    转载自http://www.dennythecow.com/?p=547,方便自己偶尔看看 在2014年的2月12日至2月22日,我去到了一个完全与世隔绝的山沟沟的一间小破院里苦修.期间,我被强制彻底 ...

  8. 项目实战No2 登陆注册

    一 导航栏返回键统一处理 自定义NavigationController,重写push方法 /*** 拦截所有push进来的子控制器* @param viewController 每一次push进来的 ...

  9. iOS开发——项目篇—高仿百思不得姐

    01 一.包装为导航控制器 UINavigationController *nav = [[UINavigationController alloc] initWithRootViewControll ...

最新文章

  1. ThoughtWorks微服务架构交流心得
  2. python从入门到精通视频-python从入门到精通视频(大全60集)
  3. oracle锁定用户名及解锁
  4. 快速查找无序数组中的第K大数?
  5. 【Linux】一步一步学Linux——uname命令(72)
  6. python 远程控制_用 Python 远程控制你的电脑
  7. createwindow 和 dialogbox的区别
  8. 在linux下安装mplayer和解码器
  9. 谢烟客---------Linux之Aho Weinberger Kernighan
  10. 圆形区域函数可视化和泊松方程求解
  11. 据称:韩乔生老师最牛的一次解说――-那是相当的经典!
  12. 零信任能彻底解决邮件安全难题
  13. 【Unity Shader】聚光灯体积光效果的简单实现
  14. Android SQLite 数据库常用命令
  15. 你们有半数以上的人留下的是gmail而不是QQMail/Foxmail的电子邮件
  16. 温度场有限容积法程序入门之六:后处理.花絮.Contour Plotter and 3D Function Grapher Together - the Applet and the Souce Co
  17. 基于计数栈的非递归二叉树遍历算法
  18. 【物联网专题】1.1_物联网基本概念_什么是物联网(IoT)?
  19. 用python编程 商品打折怎么计算_买东西打折是怎么算的!
  20. win10python3.9安装pycocotools

热门文章

  1. html中怎么让盒子模型居中,通过box盒子模型给元素内容设置居中
  2. mysql数据封装是什么_MySql数据封装操作类
  3. Java实现 LeetCode 517 超级洗衣机
  4. 那些让我印象深刻的bug--03
  5. win10 官方纯净版安装详细图解
  6. ROS系统下完成TCP通信 C语言编程
  7. leetcode刷题(三)——容斥原理
  8. flask手写汉字识别网站(已开源)
  9. 推荐一个220V控制12V的电路板继电器-220v降压控制继电器
  10. 服务器硬盘如何把硬盘装换到gpt格式化,装GPT硬盘系统的格式转换与diskpart命令使用方法...