c# - WPF one pixel-wide line sometimes disappears -


i'm trying make control draws red cross in center. want cross 1 pixel wide, , want disable antialiasing , make snap screen's pixels.

the control works, if add inside grid has splitter, when drag splitter 1 of lines disappear. if put inside grid horizontal splitter, horizontal line disappear , if put inside grid vertical splitter, vertical line disappear.

how can stop lines disappearing?

here xaml code:

<window x:class="wpftest.mainwindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:local="clr-namespace:wpftest"         title="mainwindow" height="600" width="800">     <window.resources>         <local:halfvalueconverter x:key="halfconv" />          <style targettype="line">             <setter property="stroke" value="red"/>             <setter property="strokethickness" value="1"/>             <setter property="renderoptions.edgemode" value="aliased"/>             <setter property="snapstodevicepixels" value="true" />         </style>     </window.resources>     <grid>         <grid.rowdefinitions>             <rowdefinition height="*"/>             <rowdefinition height="auto"/>             <rowdefinition height="*"/>         </grid.rowdefinitions>         <grid grid.row="2" background="black" name="grdparent">             <line x1="{binding actualwidth, elementname=grdparent, converter={staticresource halfconv}}"               y1="0"                x2="{binding actualwidth, elementname=grdparent, converter={staticresource halfconv}}"               y2="{binding actualheight, relativesource={x:static relativesource.self}}"               height="100"               />             <line x1="0"                y1="{binding actualheight, elementname=grdparent, converter={staticresource halfconv}}"               x2="{binding actualwidth, relativesource={x:static relativesource.self}}"               y2="{binding actualheight, elementname=grdparent, converter={staticresource halfconv}}"               width="100"               />         </grid>         <gridsplitter grid.row="1" height="5" horizontalalignment="stretch" background="gray" resizebehavior="previousandnext" resizedirection="rows" />     </grid> </window> 

and here code halfvalueconverter:

using system; using system.windows.data;  namespace wpftest {     public class halfvalueconverter : ivalueconverter     {         public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture)         {             return ((double)value / 2);         }          public object convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture)         {             return ((double)value * 2);         }     } } 

this how looks when drag splitter right position:

line gone

and how should look:

line visible

in order stop lines disappearing needed use uselayoutrounding="true" in addition snapstodevicepixels.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -