首页 > 其他分享 >WPF thumb Drag DragDelta,DragStarted,DragCompleted

WPF thumb Drag DragDelta,DragStarted,DragCompleted

时间:2024-08-28 18:04:48浏览次数:3  
标签:GradientStop thumb lineBrush Windows System DragCompleted DragStarted using tb

//xaml
<Window x:Class="WpfApp302.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:WpfApp302"
        mc:Ignorable="d" WindowState="Maximized"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <Style TargetType="Thumb">
            
        </Style>
    </Window.Resources>
    <Grid>
        <Canvas x:Name="cvs" Panel.ZIndex="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">            
            <Thumb x:Name="tb" Canvas.Left="100" Canvas.Top="0"
                   Background="Blue" Width="15" 
                   Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Canvas}}" 
                   DragDelta="tb_DragDelta"
                   DragStarted="tb_DragStarted" DragCompleted="tb_DragCompleted">
                <Thumb.Template>
                    <ControlTemplate>
                        <Border BorderBrush="Black" BorderThickness="2">
                            <Rectangle Fill="Blue"/>
                        </Border>
                    </ControlTemplate>
                </Thumb.Template>
            </Thumb>
        </Canvas> 
    </Grid>
</Window>




//cs
using System;
using System.Collections.Generic;
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 WpfApp302
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            LinearGradientBrush lineBrush = new LinearGradientBrush();
            lineBrush.StartPoint = new Point(0, 0);
            lineBrush.EndPoint = new Point(1, 1);
            GradientStop gs1 = new GradientStop();
            gs1.Offset = 0;
            gs1.Color = Colors.Red;
            lineBrush.GradientStops.Add(gs1);
            GradientStop gs2 = new GradientStop();
            gs2.Offset = 0.25;
            gs2.Color = Colors.Brown;
            lineBrush.GradientStops.Add(gs2);
            GradientStop gs3 = new GradientStop();
            gs3.Offset = 0.5;
            gs3.Color = Colors.OrangeRed;
            lineBrush.GradientStops.Add(gs3);
            GradientStop gs4=new GradientStop();
            gs4.Offset = 0.75;
            gs4.Color = Colors.Orange;
            lineBrush.GradientStops.Add(gs4);
            GradientStop gs5 = new GradientStop();
            gs5.Offset = 1;
            gs5.Color = Colors.Yellow;
            lineBrush.GradientStops.Add(gs5);
            cvs.Background= lineBrush;
        }

        private void tb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
        {
            double xValue = Canvas.GetLeft(tb) + e.HorizontalChange;
            Canvas.SetLeft(tb, xValue);
            //Canvas.SetTop(tb, Canvas.GetTop(tb) + e.VerticalChange);
            this.Title = $"X:{xValue}";
            double yadjust = cvs.Height + e.VerticalChange;
            double xadjust = cvs.Width + e.HorizontalChange;

            if((xadjust>=0) && (yadjust>=0))
            { 
               
            }
        }

        private void tb_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
        {
            tb.Background = Brushes.Orange;
        }

        private void tb_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
        {
            tb.Background = Brushes.Blue;
        }
    }
}

 

 

标签:GradientStop,thumb,lineBrush,Windows,System,DragCompleted,DragStarted,using,tb
From: https://www.cnblogs.com/Fred1987/p/18385271

相关文章

  • C# generate thumbnailimage via System.Drawing
    usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows;usingSystem.Windows.Data;usingSystem.Windows.Documents;usingSystem.Windows.Input;usingSystem.Windows.Media.I......
  • Thumbs.db文件怎么产生,怎样禁止产生,占用怎么删除
    一、Thumbs.db文件怎么出现的?当你的电脑开启了【显示隐藏的文件、文件夹和驱动器】,会发现有些文件夹中会出现一个名为“Thumbs.db”的文件。Thumbs.db文件是查看缩略图所产生的缓存文件,你一定是使用缩略图的形式查看图片文件了,所以才会出现这个文件,这是正常的表现,并不是什么......
  • Java图片处理Thumbnailator
    原文链接:https://zhuanlan.zhihu.com/p/604121848 Thumbnailator是Google开源的优秀图片处理的第三方Java类库,比JDK自带的库要好用的多。官网Github地址Maven依赖目前最新版本是0.4.19<dependency><groupId>net.coobird</groupId><artifactId>thumbnailator</a......
  • Springboot使用Thumbnailator压缩图片上传到阿里云OSS
    原文链接:https://blog.csdn.net/weixin_39973810/article/details/86545054前提:图片的压缩大致有两种,一种是将图片的尺寸压缩小,另一种是尺寸不变,将压缩质量,一般对于项目我们需要第一种,即用户上传一张分辨率为3840 × 2160的图片,通过上传图片接口后上传到OSS上的图片分辨率会......
  • java使用google开源工具Thumbnailator实现图片压缩
    Thumbnailator,一款google使用的开源的图片压缩工具类。github地址:https://github.com/coobird/thumbnailator优点:1、压缩程度可控制,想压缩成多小就多小。2、压缩之后图片尽可能的不失真。3、压缩速度要快。4、代码简单,依赖较少。5、可以实现对图片到编辑,如如旋转,裁切,加......
  • x.thumbnailer 修复psd缩略图/nemo-preview 自定义预览
    缩略图https://askubuntu.com/questions/1368910/how-to-create-custom-thumbnailers-for-nautilus-nemo-and-caja安装imagemagicksudoaptinstallimagemagick-6.q16/usr/share/thumbnailers/psd.thumbnailerhttps://moritzmolch.com/blog/1749.htmlcd/usr/share/thumbn......
  • WPF ListBox thumbnails and image mvvm behavior CallMethodAction
    <Windowx:Class="WpfApp108.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • MajorDoMo-thumb.php未授权RCE漏洞复现
    漏洞描述:thumb.php主要用于MajorDoMo中的缩略图生成,这个文件处理外部输入时未正确验证用户输入,攻击者可以利用该处执行恶意代码Fofa:app="MajordomoSL"POC:GET/modules/thumb/thumb.php?url=cnRzcDovL2EK&debug=1&transport=%7C%7C+%28echo+%27%5BS%5D%27%3B+id%3B+echo+%2......
  • thumbor:功能强大的图片处理库
    Github地址:https://github.com/thumbor/thumborThumbor是一个功能强大的Python图片处理库,可以用于生成、裁剪、缩放、旋转和优化图像,同时还提供了安全性和缓存等功能。本文将详细介绍Thumbor库的特性、用法,并通过丰富的示例代码展示其在实际项目中的应用。Thumbor是一个......
  • Thumbnailator处理图片
    Thumbnailator处理图片 读取源图of(String...files)of(File...files)of(InputStream...inputStreams)of(URL...urls)输出文件toFile(StringoutFilepath)toFile(FileoutFile)toOutputStream(OutputStreamos)缩放size(intwidth,intheight)width(intwidt......