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 显示图片的能力还是有点弱.比如不支持图像的缩放一类的功能,使用起来不是很方便.因此我就自己写了个简单的类. 我这 ...
随机推荐
- 【2024.09.27】NOIP2024 赛前集训-刷题训练(3)
[2024.09.27]NOIP2024 赛前集训-刷题训练(3) NOIP2018 提高组 铺设道路 算法一:模拟正常人铺路的过程,每次找区间的最小值,最小值就是本次填的高度,由于出现了若干个0位置 ...
- 在昇腾Ascend 910B上运行Qwen2.5推理
目前在国产 AI 芯片,例如昇腾 NPU 上运行大模型是一项广泛且迫切的需求,然而当前的生态还远未成熟.从底层芯片的算力性能.计算架构的算子优化,到上层推理框架对各种模型的支持及推理加速,仍有很多需要 ...
- python基础之__init__.py
如何使用 在 Python 中,当一个目录被作为包来使用时,它会在包中寻找一个名为 __init__.py 的文件.如果该文件存在,Python 会将它加载到内存中,并在其中执行所有的代码. __in ...
- 快速量产低功耗 4G 定位方案?Air201 模组来搞定!
今天我们来了解的是Air201模组快速量产低功耗 4G 定位方案,希望大家有所收获. 寻寻觅觅低功耗4G定位方案? 一个Air201就够了! --定位准.体积小.功耗低,助力行业客户快速量产! 01 ...
- 强化学习算法中log_det_jacobian的影响是否需要考虑
相关: 人形机器人-强化学习算法-PPO算法的实现细节是否会对算法性能有大的影响. https://openi.pcl.ac.cn/devilmaycry812839668/google_brax_p ...
- Linux中find命令详解
find命令 find 命令用于查找文件或目录 语法格式: find ./ -type f -name '文件名' 参数依次是:find命令,这里的./指的是当前路径,-type是选择文件类型,文件类 ...
- Django+SimpleUI
1.安装 pip install django-simpleui -i https://pypi.tuna.tsinghua.edu.cn/simple 2.修改配置文件 # 修改project的se ...
- 在PlatformIO IDE中对ESP32的CPU主频等进行配置
前言 rt,有一天开发中需要尽可能发挥ESP32的全部性能,提高主频自然是首选,在Arduino IDE中修改主频很方便,但在PlatformIO IDE中修改主频的方法网上说的却很少,今天就总结一下 ...
- windows安装gitbook并部署发布到openEuler欧拉服务器
1. 安装nodejs10 下载安装nvm https://github.com/coreybutler/nvm-windows/releases/download/1.1.9/nvm-setup.e ...
- 腾讯云对象存储COS获Veritas认证,数据安全能力再升级
近日获悉,腾讯云对象存储 COS 正式通过 Veritas 备份软件标准化测试,为数据安全再添新助力. Veritas 对 COS 的支持已经从底层打通,目前 Veritas 的 NetBackup ...