转换为WPF [英] convert to WPF

查看:71
本文介绍了转换为WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    e.Graphics.FillEllipse(Brushes.Gray,new Rectangle(ListPoints [i] .X,ListPoints [i] .Y,outerSize / 2,outerSize / 2));


这条线在winforms中表现很好。它在我在控件中单击的位置上生成一个fillEllipse。



如何为WPF做同样的事情?


解决方案

该代码适用于Windows窗体,因为它基于System.Drawing。 WPF在C#代码之上使用了XAML,您可以编写代码以在画布上生成椭圆(如果需要在应用程序本身上呈现),

< Canvas Height =" 200"宽度= QUOT; 200"> 

<! - 绘制一个蓝色内部的椭圆形。 - >
< Ellipse
Width =" 100"
高度="50"
Fill =" Gray"
Canvas.Left =" 10"
Canvas.Top =" 25" />

< / Canvas>

参见
此链接
,用于解释Ellipse和其他对象在WPF运行时中。要生成自定义大小的椭圆,可以在XAML中使用数据绑定方法,并让运行时生成所需大小的椭圆。 


如果要进行图形处理对于图像文件或其他内容,您可以在此处详细了解如何在WPF中执行基本图形,  https://docs.microsoft.com/en-us/dotnet/framework/wpf/graphics-multimedia/wpf-graphics-rendering-overview


   e.Graphics.FillEllipse(Brushes.Gray, new Rectangle(ListPoints[i].X, ListPoints[i].Y, outerSize / 2, outerSize / 2));

that line work great in winforms. It make a fillEllipse on the location I click on in the control.

how do I do the same thing for WPF?

解决方案

That code works in Windows Forms, because it is based on System.Drawing. WPF utilized XAML on top of the C# code for this, you can write the code to generate the ellipse on the canvas (if it needs to be rendered on the app itself), 

<Canvas Height="200" Width="200">

  <!-- Draws an oval with a blue interior. -->
  <Ellipse
    Width="100"
    Height="50"
    Fill="Gray"
    Canvas.Left="10"
    Canvas.Top="25" />

</Canvas>

See this link for the explanation of Ellipse and other objects in WPF runtime. To generate an ellipse of a custom size, you can use the data binding approach in XAML and have the runtime generate the ellipse for a size required. 

If you want to do the graphics for image files or something else, you can study more on how to do the basic graphics in WPF here, https://docs.microsoft.com/en-us/dotnet/framework/wpf/graphics-multimedia/wpf-graphics-rendering-overview


这篇关于转换为WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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