UWP ManipulationStarted 移动图片或控件不要滑出父容器的判断
假设自定义一个用户控件用以在父容器Grid里拖动/移动:
<UserControl
x:Class="App6.Pic"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App6"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" ManipulationMode="All"
ManipulationStarted="UserControl_ManipulationStarted" ManipulationDelta="UserControl_ManipulationDelta"
d:DesignHeight="300" RenderTransformOrigin="0.5,0.5"
d:DesignWidth="400">
<UserControl.RenderTransform>
<TranslateTransform x:Name="t" />
</UserControl.RenderTransform>
<Grid Background="AliceBlue">
<TextBlock Name="txt" Text="" />
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation; // The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 namespace App6
{
public sealed partial class Pic : UserControl
{
public Pic()
{
this.InitializeComponent(); } private void UserControl_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{ } private void UserControl_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{ this.t.X += e.Delta.Translation.X;
this.t.Y += e.Delta.Translation.Y;
txt.Text = "" + (Parent as Grid).ActualWidth + ", " + t.X + this.Margin.Left + this.ActualWidth / 2;
//判断核设置移动范围限制在父容器内
if ((Parent as Grid).ActualWidth < this.Margin.Left+ t.X + this.Width)//to right
{
this.t.X = (Parent as Grid).ActualWidth - (this.Margin.Left + this.Width);
} if (0 >this.Margin.Left + t.X )//to left
{
this.t.X = - this.Margin.Left ;
} if (0 > this.Margin.Top + t.Y)//to top
{
this.t.Y= -this.Margin.Top;
} if ((Parent as Grid).ActualHeight < this.Margin.Top + t.Y + this.Height)//to bottom
{
this.t.Y = (Parent as Grid).ActualHeight - (this.Margin.Top + this.Height);
} } }
}
UWP ManipulationStarted 移动图片或控件不要滑出父容器的判断的更多相关文章
- UI-UIImageView的图片填充方式(contentMode)_图片作为控件背景图的拉伸方式(stretch)介绍
常用图片填充方式 这里只介绍三个最常用的图片填充方式 UIViewContentModeScaleToFill模式会导致图片变形.例如: UIViewContentModeScaleAspectFit ...
- 我写的一个 Qt 显示图片的控件
Qt 中没有专门显示图片的控件.通常我们会使用QLabel来显示图片.可是QLabel 显示图片的能力还是有点弱.比方不支持图像的缩放一类的功能.使用起来不是非常方便. 因此我就自己写了个简单的类. ...
- Android开发技巧——定制仿微信图片裁剪控件
拍照--裁剪,或者是选择图片--裁剪,是我们设置头像或上传图片时经常需要的一组操作.上篇讲了Camera的使用,这篇讲一下我对图片裁剪的实现. 背景 下面的需求都来自产品. 裁剪图片要像微信那样,拖动 ...
- MFC入门(三)-- MFC图片/文字控件(循环显示文字和图片的小程序)
惯例附上前几个博客的链接: MFC入门(一)简单配置:http://blog.csdn.net/zmdsjtu/article/details/52311107 MFC入门(二)读取输入字符:http ...
- 关于IOS某图片添加控件,图片从相册或拍照保存后,再次进入时点击放大图无法显示的问题
某图片添加控件: https://github.com/XZTLLQ/LQPhotoPickerDemo 问题: 标题已说明 代码块: NSArray *alAssetUrl =(NSMutableA ...
- 图片剪裁控件——ClipImageView
这段时间在做自己的项目时,须要使用到图片剪裁功能,当时大概的思考了一些需求.想到了比較简单的实现方法.因此就抽了点时间做了这个图片剪裁控件--ClipImageView 这里先贴上ClipImageV ...
- Android实现图片滚动控件,含页签功能,让你的应用像淘宝一样炫起来
首先题外话,今天早上起床的时候,手滑一下把我的手机甩了出去,结果陪伴我两年半的摩托罗拉里程碑一代就这么安息了,于是我今天决定怒更一记,纪念我死去的爱机. 如果你是网购达人,你的手机上一定少不了淘宝客户 ...
- 用MVVM模式开发中遇到的零散问题总结(5)——将动态加载的可视元素保存为图片的控件,Binding刷新的时机
原文:用MVVM模式开发中遇到的零散问题总结(5)--将动态加载的可视元素保存为图片的控件,Binding刷新的时机 在项目开发中经常会遇到这样一种情况,就是需要将用户填写的信息排版到一张表单中,供打 ...
- UWP入门(五)--控件模板
原文:UWP入门(五)--控件模板 通过在 XAML 框架中创建控件模板,你可以自定义控件的可视结构和可视行为(eg:勾选框的三种状态). 控件有多个属性,如 Background.Foregroun ...
- 一个 Qt 显示图片的控件(继承QWidget,使用QPixmap记录图像,最后在paintEvent进行绘制,可缩放)
Qt 中没有专门显示图片的控件,通常我们会使用QLabel来显示图片.但是QLabel 显示图片的能力还是有点弱.比如不支持图像的缩放一类的功能,使用起来不是很方便.因此我就自己写了个简单的类. 我这 ...
随机推荐
- 人形机器人是未来?6只手臂加AI模型,异形机器人重塑种植业。
图源:reddit user IlustriousTea 近日,一则视频在媒体上引起了人们的讨论.国外一处苹果园里,机械嗡鸣声中,六只机械手熟练且快速地采摘成熟的苹果. 这是2018年于美国加利福尼亚 ...
- Java面试题及答案整理汇总(2024最新版)
前言 辞退了老板,准备找下家,又要开始面试了,不得不准备准备八股文,还是很有必要针对性的刷一些题,很多朋友的实战能力很强,但是理论比较薄弱,要多准备准备理论知识,攻克面试官.这是我在全网寻找稍微比较完 ...
- C# 删除Word文档中的段落
在编辑Word文档时,我们有时需要调整段落的布局.删除不必要的段落以优化文档的结构和阅读体验.本文将通过以下3个简单示例演示如何使用免费.NET库删除Word文档中的段落 . C# 删除Word中的指 ...
- 动态避障-图扑自动寻路 3D 可视化
自动寻路是机器人导航的核心技术,其原理主要涉及机器人与环境之间的复杂信息交互与处理.在自动寻路过程中,机器人依靠先进的传感器系统,如高清摄像头.精密激光雷达和灵敏超声波装置,全方位感知周围环境.这些传 ...
- base64编码图片二进制数据后直接保存在html文件中
相关内容: 在markdown编辑器中嵌入base64图片 看到一个帖子,那就是base64编码用来http服务中对二进制文件编码,那么可以不可以直接在html文件中使用base64编码后的字符串来表 ...
- MindSpore-2.4版本中的一些新特性
技术背景 在前面的一篇博客中我们介绍了MindSpore-2.4-gpu的安装和其中可能出现的一些问题.这里我们在安装完成之后,可以尝试使用一些MindSpore新版本的特性.那么在安装之后,如果是使 ...
- highcharts在vue中的应用
1.安装命令 npm install highcharts --save 2.在页面中按需引入 import Highcharts from 'highcharts/highstock'; impor ...
- Mybatis【3】-- Mybatis使用工具类读取配置文件以及从属性读取DB信息
代码直接放在Github仓库[https://github.com/Damaer/Mybatis-Learning ],可直接运行,就不占篇幅了. 1.使用工具类获取sqlSession实例对象 在上 ...
- 解析HTML字符串成AST树
1. 如何将一个字符传转换成一个AST树结构. 直接上代码: const attribute = /^\s*([^\s"'<>\/=]+)(?:\s*(=)\s*(?:" ...
- 论文泛读《PICCOLO : Exposing Complex Backdoors in NLP Transformer Models》
发表时间:2022 期刊会议:IEEE Symposium on Security and Privacy (SP) 论文单位:Purdue University 论文作者:Yingqi Liu, G ...