如何避免单个像素线在wpf中消失?

时间:2015-04-10 02:28:40

标签: c# wpf snapstodevicepixels

我使用路径element(StrokeThickness="1" SnapsToDevicePixels="True") 在网格中。我想调整窗口大小,Grid元素由Viewbox元素包装。

问题

当我调整窗口大小时,Path会消失一段时间。如果我将SnapsToDevicePixels变为false,则Path元素可能会模糊,这不是我想要的。

如何避免单个像素线消失?

XAML代码:

<Window x:Class="WpfApplication2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="207" Width="475">
   <Viewbox Stretch="Fill">
       <Grid Height="320" Width="517">
          <Path Data="M0,0 H1 z" StrokeThickness="1" Stroke="Black" Margin="72,73,79,218" Stretch="Fill" SnapsToDevicePixels="True" MinHeight="1"/>
       </Grid>
   </Viewbox>

可惜我没有声誉来发布运行时效果。

1 个答案:

答案 0 :(得分:0)

我已经用放置在Viewbox中的分隔符尝试了相同的问题。其中一些消失了一些解决方案。要解决此问题,我将其替换为高度为1像素的边框:

< Border Background="DarkGray" Grid.Row="0" Grid.ColumnSpan="7" Height="1" />

这避免了一个像素的单行在viewBox中消失。 希望它对您也有用。