帆布WPF中使用缩放代码背后 [英] Canvas zooming in WPF using code behind

查看:162
本文介绍了帆布WPF中使用缩放代码背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的场景是:



结果
我有它绘制不同的图的画布。现在的要求是放大到后面的使用或者使用C#或VB代码中的画布。另外我需要将变焦代码在某些DLL,这样我可以通过我的应用程序重复使用同一套代码。



现在我的问题是如何做到这一点。 ...



我曾尝试下面的代码请看看..

 公共主窗口()
{
的InitializeComponent();

canvas.MouseEnter + =新MouseEventHandler(canvas_MouseEnter);
canvas.MouseWheel + =新MouseWheelEventHandler(canvas_MouseWheel);
}

无效canvas_MouseWheel(对象发件人,MouseWheelEventArgs E)
{
双高= canvas.ActualHeight;
双倍宽度= canvas.ActualWidth;
双重变焦= e.Delta;
高+ = 2;
宽+ = 2;
ScaleTransform SC =新ScaleTransform(宽度,高度);
canvas.LayoutTransform = SC;
canvas.UpdateLayout();
}


解决方案

我相信你在找什么的是一个缩放行为即可。 行为是封装了某种形式的互动行为的对象。我已经看到了缩放行为,你应该能够用于项目的几个例子。您应该能够使用或修改以下...



中的一个

Here the scenario is:


I have a canvas with different diagrams drawn on it. Now the requirement is to zoom into the canvas using the code behind either using C# or VB. Moreover I need to place the zoom code in some dll so that i can reuse the same set of code through out my application.

Now my question is how to do this....

I have tried the following code pls have a look..

public MainWindow()
{
    InitializeComponent();

    canvas.MouseEnter += new MouseEventHandler(canvas_MouseEnter);
    canvas.MouseWheel += new MouseWheelEventHandler(canvas_MouseWheel);
}

void canvas_MouseWheel(object sender, MouseWheelEventArgs e)
{
    double height = canvas.ActualHeight;
    double width = canvas.ActualWidth;
    double zoom = e.Delta;
    height += 2;
    width += 2;
    ScaleTransform sc = new ScaleTransform(width, height);
    canvas.LayoutTransform = sc;
    canvas.UpdateLayout();
}

解决方案

I believe what you are looking for is a zoom behavior. Behaviors are objects that encapsulate some form of interactive behavior. I've seen several examples of "Zoom Behaviors" that you should be able to use for your project. You should be able to use or modify one of the following...

这篇关于帆布WPF中使用缩放代码背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆