如何避免WPF中的单个像素行消失? [英] how to avoid a single pixel line disappear in wpf?
问题描述
我使用路径element(StrokeThickness="1" SnapsToDevicePixels="True")
在网格中.我想调整窗口大小,Grid元素由Viewbox元素包装.
I use a Path element(StrokeThickness="1" SnapsToDevicePixels="True")
in Grid. I want to resize the window, the Grid element is wrapped by a Viewbox element.
问题
当我调整窗口大小时,路径将消失一段时间.如果将SnapsToDevicePixels设置为false,则Path元素可能会模糊,这不是我想要的.
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.
如何避免单个像素线消失?
How to avoid a single pixel line dispear?
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.
推荐答案
我已经对放置在Viewbox中的分隔符进行了相同的实验.其中一些消失了一些解决方案.要解决此问题,我将其替换为高度为1像素的边框:
I have experimented the same problem with separators put in a Viewbox. Some of these disappear for some resolutions. To fix it, I replace them with border with 1 pixel height :
< Border Background="DarkGray" Grid.Row="0" Grid.ColumnSpan="7" Height="1" />
这避免了一个像素的单行在viewBox中消失. 希望它对您也有用.
This avoid single line of one pixel to disappear in viewBox. Hope it could be useful for you too.
这篇关于如何避免WPF中的单个像素行消失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!