什么是WPF的Windows相当于Paint事件窗体Region.Xor? [英] What is WPF equivalent of Windows Forms Region.Xor in Paint event?

查看:708
本文介绍了什么是WPF的Windows相当于Paint事件窗体Region.Xor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这个的WinForms code移动到WPF,但没有油漆事件。

 私人无效的OnPaint(对象发件人,PaintEventArgs的E)
{
    VAR区域=新区域(新的Rectangle(0,0,this.Width,this.Height));
    VAR矩形=新的Rectangle(0,0,50,50);
    region.Xor(矩形);
    e.Graphics.FillRegion(Brushes.Black,区);
}


解决方案

WPF并不像在图形方面的WinForms工作。你不能真正绘制形状,你必须将其放置到您的内容。

几何 应作为一个很好的替代地区。您可以使用 Geometry.Combine 并指定 GeometryCombineMode .XOR 复制您的绘图code。

RectangleGeometry 是你怎么做的矩形。类似的还有类等形状。

要实际显示几何,把它放在一个的 路径 ,可以用作控制的内容。

I'm trying to move this WinForms code to WPF, but there is no Paint event.

private void OnPaint(object sender, PaintEventArgs e)
{
    var region = new Region(new Rectangle(0, 0, this.Width, this.Height));
    var rectangle = new Rectangle(0, 0, 50, 50);
    region.Xor(rectangle);
    e.Graphics.FillRegion(Brushes.Black, region);
}

解决方案

WPF doesn't work like WinForms in terms of graphics. You can't actually draw shapes, you have to place them into your content.

Geometry should serve as a good replacement for Region. You can use Geometry.Combine and specify GeometryCombineMode.Xor to replicate your drawing code.

RectangleGeometry is how you make rectangles. There are similar classes for other shapes.

To actually display the Geometry, put it in a Path, which can be used as a control's content.

这篇关于什么是WPF的Windows相当于Paint事件窗体Region.Xor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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