Question

Pourquoi le chemin et Polyligne ont rendus différents dans WPF?

Ce qui se passe en code et mélange, peut-être un je manque quelque chose ou ce est juste un effet anti aliasing.

<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>

échantillon d'image du mélange: http://img190.imageshack.us/img190/2965/wpfsmaple.png

Système de développement: Windows XP SP2, VS 2008 SP1 +

Était-ce utile?

La solution

Il a à voir avec les modes de dessin d'objets non textuels. J'ai essayé définissant l'objet polyligne comme l'article lié ci-dessous dit et il ne le faire paraître comme le chemin.

Alors, réponse courte est qu'il doit faire avec l'anti-aliasing. Voici l'article: lignes de pixel

Si vous voulez que la commande ici, il est, donnez votre polyligne un nom et puis ajoutez ce qui suit au code derrière.

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

Votre changement XAML ici:

<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>

Cela rendra votre objet polyligne regarder comme votre objet Path. Cependant la modification du chemin à utiliser sans précision ne fait rien pour que vous puissiez faire vos autres objets ressemblent au chemin mais pas vice versa.

Autres conseils

Mettre cela sur votre chemin ou Polyline balise XAML

RenderOptions.EdgeMode="Aliased"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top