0

I have two components in wpf and want to make a 1 pixel dotted line between them. Have not managed to achieve this using any on the tricks mentioned at stackoverflow.

This empty project with just this wpf code added demonstrates the problem, when the app is resized the line will disappear from time to time. Removing RenderOptions.EdgeMode="Aliased" will instead make the line 2 pixels wide.

<Window x:Class="DottedLineExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DottedLineExample"
        mc:Ignorable="d"
        Title="MainWindow" Height="100" Width="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="1" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Line 
            Grid.Row="1" 
            HorizontalAlignment="Stretch" 
            Stroke="Black" 
            X2="{Binding ActualWidth, RelativeSource={RelativeSource Self}}" 
            StrokeDashArray="4 4" 
            StrokeThickness="1"
            SnapsToDevicePixels="True"
            UseLayoutRounding="True"
            RenderOptions.EdgeMode="Aliased"
            />
    </Grid>
</Window>
GulPaprika
  • 31
  • 5
  • Possible duplicate of [http://stackoverflow.com/questions/2879033/how-do-you-draw-a-line-on-a-canvas-in-wpf-that-is-1-pixel-thick](http://stackoverflow.com/questions/2879033/how-do-you-draw-a-line-on-a-canvas-in-wpf-that-is-1-pixel-thick) – Dbuggy Sep 29 '16 at 13:50
  • That is from code and the solution mentioned there is implemented above and it still doesn't work. – GulPaprika Sep 30 '16 at 11:38

0 Answers0