首页 > 其他分享 >WPF Image enlarge via MouseWheel, selected image center does not shift

WPF Image enlarge via MouseWheel, selected image center does not shift

时间:2024-05-29 17:00:58浏览次数:13  
标签:via MouseWheel center img Windows System ZoomLevel using public

//xaml
<Window x:Class="WpfApp123.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp123"
        mc:Ignorable="d" WindowState="Maximized"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Image x:Name="img" Source="{Binding ImgUrl,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
               MouseWheel="img_MouseWheel"> 
        </Image>
    </Grid>
</Window>


//xaml.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp123
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window,INotifyPropertyChanged
    {
        #region Properties
        private string imgUrl;
        public string ImgUrl
        {
            get
            {
                return imgUrl;
            }
            set
            {
                imgUrl = value;
                OnPropertyChanged(nameof(ImgUrl));
            }
        }

        private double zoomLevel=1.0;
        public double ZoomLevel
        {
            get
            {
                return zoomLevel;
            }
            set
            {
                zoomLevel = value;
                OnPropertyChanged(nameof(ZoomLevel));
            }
        }

        #endregion
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = this;
            ImgUrl = @"..\..\Images\cl.jpg";
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propName)
        {
            var handler = PropertyChanged;
            if(handler!=null)
            {
                handler?.Invoke(this, new PropertyChangedEventArgs(propName));
            }
        }

        private void img_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            img.RenderTransform = null;
            var position = e.MouseDevice.GetPosition(img);
            if (e.Delta>0)
            {
                ZoomLevel *= 1.2;
            }
            else
            {
                ZoomLevel /= 1.2;
            }
            img.RenderTransform = new ScaleTransform(ZoomLevel, ZoomLevel, position.X, position.Y);
        }
    }
}

 

Amplify/enlarge left eye

 

标签:via,MouseWheel,center,img,Windows,System,ZoomLevel,using,public
From: https://www.cnblogs.com/Fred1987/p/18220665

相关文章

  • [基础]tfcenter mount将Webdav服务挂载成本地磁盘(可显示使用空间)
    1、下载tfcentermount软件(1)点击官网 tfcenter官网 后下载挂载软件(2)以windows挂载为例,下载windows软件包(3)解压软件包,如下图所示2、配置tfcenter挂载(1)以管理员方式运行上图的tfcenter-mount.bat文件选择1安装tfcentermount服务到系统中选择3启动tfcentermount服务......
  • Center of Mass
     -foranarc:$\frac{r\sin\theta}{\theta}$fromthecentremoment:$\int_{-\theta}^\thetar\cos\theta\cdotr{\rmd}\theta=r^2\cdot[\sin\theta]|_{-\theta}^\theta=2r^2\sin\theta$mass:$2r\theta$so$2r^2\sin\theta\div2r\theta=\fr......
  • 【VMware vCenter】在不重启的情况下重置vCenter Server的root密码。
    VMware提供了一种方法,可以在不用重新启动vCenterServer进入grub引导至单用户模式的情况下重置root的密码,这种方法使用的是通过SSO管理员账号([email protected])登录到vCenterServer的VAMI管理界面,在右上角的操作菜单里提供更改root用户密码的选项。但是,上述方法仅适......
  • VMware vCenter Server 7.0 Update 3q 下载 - 集中管理 vSphere 环境
    VMwarevCenterServer7.0Update3q下载-集中管理vSphere环境请访问原文链接:https://sysin.org/blog/vmware-vcenter-7-u3/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgVMwarevCenterServer是一款高级服务器管理软件,提供了一个集中式平台来控制vSphere......
  • WPF Image ZoomIn ZoomOut via MouseWheel
    //xaml<Windowx:Class="WpfApp104.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......
  • [Paper Reading] BEVFormer: Learning Bird’s-Eye-View Representation from Multi-C
    BEVFormer:LearningBird’s-Eye-ViewRepresentationfromMulti-CameraImagesviaSpatiotemporalTransformerslink时间:22.07机构:NanjingUniversity&&ShanghaiAILaboratoryTL;DR利用Transformer的Attention机制融合时空特征信息,在nuScenes测试集上达到SOTA精度,同时......
  • CF527E Data Center Drama 题解
    @目录题目题意题解思路详解注意事项代码AC记录尾声题目CF527EDataCenterDrama·戳这里题意给定一张$n$个点$m$条边的连通无向图。你需要加尽可能少的边,然后给所有边定向,使得每一个点的出入度都是偶数。边可以是自环,也可以有重边。$n\le10^5$,$m\le2\times1......
  • RAG Project with Ollama and LangChain via Gradio Interface
    RAGProjectwithOllamaandLangChainviaGradioInterfacehttps://github.com/fanqingsong/rag-ollama-langchainThisrepositoryhoststheimplementationofaRetrieval-AugmentedGeneration(RAG)projectleveragingthecapabilitiesofOllamatorunopen-so......
  • Cisco Catalyst Center 2.3.7.5-VA - 网络管理和自动化
    CiscoCatalystCenter2.3.7.5-VA-网络管理和自动化CiscoCatalystCenter-NetworkManagementandAutomation请访问原文链接:CiscoCatalystCenter2.3.7.5-VA-网络管理和自动化,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgCiscoCatalystCenter节约时......
  • vcenter创建数据中心加入ESXI主机
    vcenter创建数据中心加入ESXI主机 右键选择vcenter主机,点新建数据中心 2、点确定  3、对Datacenter右键,然后选择添加主机 4、添加主机IP地址 5、添加用户密码,然后下一页 6、点是 7、会显示摘要,按下一页 8、分配许可证 9、按是 10、按下一......