为什么WPF中路径和折线有不同的渲染?

发布于 2024-08-16 23:42:12 字数 1190 浏览 7 评论 0原文

为什么WPF中路径和折线有不同的渲染?

这在代码和混合中都发生,也许我错过了一些东西或这个 只是一个抗锯齿效果。

<Window
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 x:Class="GeometryMonky.Window1"
 x:Name="Window"
 Title="Window1"
 Width="640" Height="480" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">

 <Grid x:Name="LayoutRoot">
  <Path Fill="#FFFFFFFF" Stretch="Fill" Stroke="#FF0000FF" Margin="100,10,0,0" Data="M289,39 L333,173" Width="1" HorizontalAlignment="Left" Height="100" StrokeThickness="1"/>

  <Polyline Stroke="#FF0000FF" Margin="115,178,417,168" StrokeThickness="1" Width="100" Height="100">
   <Polyline.Points>
    <Point>10,0</Point>
    <Point>10,100</Point>
   </Polyline.Points>
  </Polyline>
 </Grid>
</Window>

Blend 的图像样本: http://img190.imageshack.us/img190/2965/wpfsmaple.png

开发系统: WinXP SP2、VS 2008 + SP1

Why the Path and Polyline have different renderings in WPF?

This is happening both in code and blend, maybe a I missing something or this
is just a anti aliasing effect.

<Window
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 x:Class="GeometryMonky.Window1"
 x:Name="Window"
 Title="Window1"
 Width="640" Height="480" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">

 <Grid x:Name="LayoutRoot">
  <Path Fill="#FFFFFFFF" Stretch="Fill" Stroke="#FF0000FF" Margin="100,10,0,0" Data="M289,39 L333,173" Width="1" HorizontalAlignment="Left" Height="100" StrokeThickness="1"/>

  <Polyline Stroke="#FF0000FF" Margin="115,178,417,168" StrokeThickness="1" Width="100" Height="100">
   <Polyline.Points>
    <Point>10,0</Point>
    <Point>10,100</Point>
   </Polyline.Points>
  </Polyline>
 </Grid>
</Window>

Image sample from Blend:
http://img190.imageshack.us/img190/2965/wpfsmaple.png

Development system:
WinXP SP2, VS 2008 + SP1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一梦等七年七年为一梦 2024-08-23 23:42:12

它与非文本对象的绘制模式有关。我尝试像下面链接的文章所述设置折线对象,它确实使它看起来就像路径一样。

所以,简短的回答是它与抗锯齿有关。这是文章:单像素线

如果您想要命令在这里,给你的折线一个名称,然后将以下内容添加到后面的代码中。

public partial class MainWindow : Window
{
    public MainWindow()
    {
        this.InitializeComponent();
        // THIS IS THE LINE THATS IMPORTANT
        pLine.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
   }
}

您的 xaml 在此更改:

<Polyline x:Name="pLine" Stroke="#FF0000FF" Margin="115,178,417,168" StrokeThickness="1" Width="100" Height="100">
  <Polyline.Points>
    <Point>10,0</Point>
    <Point>10,100</Point>
   </Polyline.Points>
</Polyline>

这将使您的折线对象看起来就像您的 Path 对象。但是,将路径更改为使用未指定不会执行任何操作,因此您可以使其他对象看起来与路径相似,但反之则不然。

It has to do with drawing modes of non-text objects. I tried setting the polyline object like the article linked below says and it does make it look just like the path.

So, short answer is it has to do with anti-aliasing. Here is the article: Single Pixel Lines

If you want the command here it is, give your polyline a Name and then add the following to the code behind.

public partial class MainWindow : Window
{
    public MainWindow()
    {
        this.InitializeComponent();
        // THIS IS THE LINE THATS IMPORTANT
        pLine.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
   }
}

Your xaml change here:

<Polyline x:Name="pLine" Stroke="#FF0000FF" Margin="115,178,417,168" StrokeThickness="1" Width="100" Height="100">
  <Polyline.Points>
    <Point>10,0</Point>
    <Point>10,100</Point>
   </Polyline.Points>
</Polyline>

This will make your polyline object look just like your Path object. However changing the Path to use unspecified does not do anything so you can make your other objects look similar to the path but not vice versa.

别再吹冷风 2024-08-23 23:42:12

将其放入 Path 或 Polyline xaml 标记中

RenderOptions.EdgeMode="Aliased"

Put this in your Path or Polyline xaml tag

RenderOptions.EdgeMode="Aliased"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文