简体   繁体   English

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

[英]how to avoid a single pixel line disappear in wpf?

I use a Path element(StrokeThickness="1" SnapsToDevicePixels="True") in Grid.我在网格中使用路径element(StrokeThickness="1" SnapsToDevicePixels="True") I want to resize the window, the Grid element is wrapped by a Viewbox element.我想调整窗口大小,Grid 元素被 Viewbox 元素包裹。

Problem问题

When I resize the window, the Path will disappear some time.当我调整窗口大小时,路径会消失一段时间。 If I turn SnapsToDevicePixels to false, the Path element may blur which is not what I want.如果我将 SnapsToDevicePixels 设置为 false,则 Path 元素可能会模糊,这不是我想要的。

How to avoid a single pixel line dispear?如何避免单个像素线消失?

the XAML code: 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>

Pity for I have no reputation to post the runtime effect.可惜我没有发布运行时效果的声誉。

I have experimented the same problem with separators put in a Viewbox.我已经用放置在 Viewbox 中的分隔符试验了同样的问题。 Some of these disappear for some resolutions.其中一些会因某些分辨率而消失。 To fix it, I replace them with border with 1 pixel height :为了修复它,我用 1 像素高度的边框替换它们:

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

This avoid single line of one pixel to disappear in viewBox.这避免了一个像素的单行在 viewBox 中消失。 Hope it could be useful for you too.希望它对你也有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM