7

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.

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.

How to avoid a single pixel line dispear?

the XAML code:

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

RambleInX
  • 143
  • 11
  • I assume it disappears on specific height values (consistently)? Possibly only odd ones or some other pattern? – SimpleVar Apr 10 '15 at 02:38
  • have you met it before? the problem is that if the strokethickness is 3 pixel, then resize the window a little, it may be 2 pixel some time. – RambleInX Apr 10 '15 at 03:08
  • 2
    Just don't put it in Viewbox. A Viewbox scales the rendered output of its child element, not any geometries that may be contained in its tree, so what did you expect? – Clemens Apr 10 '15 at 06:55
  • I want the line can be scaled and have a clear edge. in the process of magnification, the line should keep its width, such as one pixel. and then to two pixels. but not one pixel and then may be disapear and then one pixel, two pixels, and again turn to one pixel...I think it may be a bug in wpf – RambleInX Apr 10 '15 at 13:21
  • I also see the VisualBrush will lost line like ViewBox.https://stackoverflow.com/q/44495238/6116637 – lindexi Jun 12 '17 at 09:58

1 Answers1

0

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

This avoid single line of one pixel to disappear in viewBox. Hope it could be useful for you too.

David Buck
  • 3,752
  • 35
  • 31
  • 35
Ced
  • 46
  • 1
  • 10