假设自定义一个用户控件用以在父容器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 移动图片或控件不要滑出父容器的判断的更多相关文章

  1. UI-UIImageView的图片填充方式(contentMode)_图片作为控件背景图的拉伸方式(stretch)介绍

    常用图片填充方式 这里只介绍三个最常用的图片填充方式 UIViewContentModeScaleToFill模式会导致图片变形.例如: UIViewContentModeScaleAspectFit ...

  2. 我写的一个 Qt 显示图片的控件

    Qt 中没有专门显示图片的控件.通常我们会使用QLabel来显示图片.可是QLabel 显示图片的能力还是有点弱.比方不支持图像的缩放一类的功能.使用起来不是非常方便. 因此我就自己写了个简单的类. ...

  3. Android开发技巧——定制仿微信图片裁剪控件

    拍照--裁剪,或者是选择图片--裁剪,是我们设置头像或上传图片时经常需要的一组操作.上篇讲了Camera的使用,这篇讲一下我对图片裁剪的实现. 背景 下面的需求都来自产品. 裁剪图片要像微信那样,拖动 ...

  4. MFC入门(三)-- MFC图片/文字控件(循环显示文字和图片的小程序)

    惯例附上前几个博客的链接: MFC入门(一)简单配置:http://blog.csdn.net/zmdsjtu/article/details/52311107 MFC入门(二)读取输入字符:http ...

  5. 关于IOS某图片添加控件,图片从相册或拍照保存后,再次进入时点击放大图无法显示的问题

    某图片添加控件: https://github.com/XZTLLQ/LQPhotoPickerDemo 问题: 标题已说明 代码块: NSArray *alAssetUrl =(NSMutableA ...

  6. 图片剪裁控件——ClipImageView

    这段时间在做自己的项目时,须要使用到图片剪裁功能,当时大概的思考了一些需求.想到了比較简单的实现方法.因此就抽了点时间做了这个图片剪裁控件--ClipImageView 这里先贴上ClipImageV ...

  7. Android实现图片滚动控件,含页签功能,让你的应用像淘宝一样炫起来

    首先题外话,今天早上起床的时候,手滑一下把我的手机甩了出去,结果陪伴我两年半的摩托罗拉里程碑一代就这么安息了,于是我今天决定怒更一记,纪念我死去的爱机. 如果你是网购达人,你的手机上一定少不了淘宝客户 ...

  8. 用MVVM模式开发中遇到的零散问题总结(5)——将动态加载的可视元素保存为图片的控件,Binding刷新的时机

    原文:用MVVM模式开发中遇到的零散问题总结(5)--将动态加载的可视元素保存为图片的控件,Binding刷新的时机 在项目开发中经常会遇到这样一种情况,就是需要将用户填写的信息排版到一张表单中,供打 ...

  9. UWP入门(五)--控件模板

    原文:UWP入门(五)--控件模板 通过在 XAML 框架中创建控件模板,你可以自定义控件的可视结构和可视行为(eg:勾选框的三种状态). 控件有多个属性,如 Background.Foregroun ...

  10. 一个 Qt 显示图片的控件(继承QWidget,使用QPixmap记录图像,最后在paintEvent进行绘制,可缩放)

    Qt 中没有专门显示图片的控件,通常我们会使用QLabel来显示图片.但是QLabel 显示图片的能力还是有点弱.比如不支持图像的缩放一类的功能,使用起来不是很方便.因此我就自己写了个简单的类. 我这 ...

随机推荐

  1. house of banana

    条件: 1.任意地址写一个堆地址 2.触发exit函数 3.能泄露堆地址和基地址 原理: 伪造 fini_array 赋值用到的结构体 从而控制程序exit时的程序执行流 ld.so 中存在 _rtl ...

  2. ABC 363

    ABC 363 D - Palindromic Number 复盘一下几个细节: 最后得到的 \(n\) 代表的是答案在长度为 \(i\) 的回文数中排第几,所以最终答案要加上长度更短的 \(1 \s ...

  3. NOIP2024模拟12:孤帆远影

    NOIP2024模拟12:孤帆远影 听了机房同学的讨论,于是T1死磕冒泡和逆序对做法.最后只得了40pts. 思想对了,但不是自己的做法. 还是要坚持自己想,坚持自己可以想出来,不要被任何人带偏. T ...

  4. 八、Spring Boot集成Spring Security之前后分离认证最佳实现对接测试

    前言 本文介绍前后分离认证最佳实现的对接测试,使用postman或者其他熟悉的测试工具,配合以下内容观看效果更佳!!! 什么是前后分离认证流程最佳方案,为什么这么设计?请查看六.Spring Boot ...

  5. if else的多种替换方式

    1)利用逻辑判断的短路运算来实现 && 和 ||(&& 中第一个表达式为假就不会去处理第二个表达式,|| 则相反) // if为真 if (bool) { value ...

  6. 解决window.close()在谷歌浏览器不起作用

    简单明了直接上解决方法: let url = ' '; // 空字符串中间要加空格 window.open(url, '_self').close();

  7. 2022-2023 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2022)

    F. Foreign Football 一共有\(n\)支队伍,每支队伍的名称为\(s_i\),给定一个\(n \times n\)的矩阵,\(a_{i,j}\)代表第\(i\)支队伍和第\(j\)支 ...

  8. 小白PDF阅读器重排版时的自动提取背景色功能介绍及实现

    小白PDF阅读器在1.35之前的版本对于有深色背景的页面重拍版时并不太完美.对于深色背景区域主要表现在不能分割排版和重排后页面元素割裂感明显.小白PDF阅读器在1.35版本主要针对这两个问题进行了优化 ...

  9. (三)Springboot + vue + 达梦数据库构建RBAC权限模型前后端分离脚手架保姆级教程(前端项目)

    XX后台管理系统 1.技术选型与环境要求 1.1 项目技术选型 1.1.1 前端技术 HTML 5 CSS 3 lavaScript Vue Element UI 1.1.2 后端技术 SpringB ...

  10. C++ Builder 开发64程序 使用AnsiString的ToInt和ToDouble会内存泄漏

    AnsiString str="adsfaga"; try { int v=str.ToInt(); } catch(...) { } 上面的代码,在C++ Builder 10 ...