编程语言
首页 > 编程语言> > c#-为什么在WPF中,路径和折线具有不同的渲染?

c#-为什么在WPF中,路径和折线具有不同的渲染?

作者:互联网

为什么路径和折线在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

解决方法:

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

因此,简短的答案是它与抗锯齿有关.这是文章:Single Pixel Lines

如果您要使用此命令,请为折线命名,然后将以下内容添加到后面的代码中.

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对象.但是,将Path更改为使用unspecified并不会执行任何操作,因此您可以使其他对象看起来与path相似,反之则不然.

标签:polyline,path,wpf,xaml,c
来源: https://codeday.me/bug/20191024/1919328.html