Tech Off Thread

7 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

WPF a "double line" stroke possible?

Back to Forum: Tech Off
  • User profile image
    MasterPi

    I'm trying to edit the appearance of a line in WPF. Specifically, I want two lines as my stroke, like "==========" as opposed to "-------------". I tried creating a visual brush and adding two lines, but the result was strange in that it connected the two lines as one line, instead of separating them in parallel.

                        <VisualBrush>
                            <VisualBrush.Visual>
                                <Canvas>
                                    <Line Stroke="Black" X1="0" Y1="0"
                                          X2="100" Y2="0"/>
                                    <Line Stroke="Blue" X1="0" Y1="0"
                                          X2="100" Y2="0" Canvas.Left="10"/>
                                </Canvas>
                            </VisualBrush.Visual>
                        </VisualBrush>

     

    Is there an easy way to do this? The line will be rotated and resized. I've gotten ideas about using a rectangle with no fill and colored stroke, but the rectangle's orientation stays fixed as you rotate the line.

     

    (In case this at all matters, I'm trying to change the line stroke for Telerik diagram connections)

  • User profile image
    cheong

    Is that because they're on the same Canvas, so when you move it to left by 10 pixels, both lines got moved.

    I think I'll add Line.RenderTransfrom and then a TranslateTransform with .X changed to the second line.

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified
  • User profile image
    MasterPi

    AFAIK, Canvas.Left on a child element sets that element's offset within its parent. It's not moving the entire canvas.

  • User profile image
    cheong

    @MasterPie:From MSDN documentation of Canvas.Left:

    A Double that represents the offset position from the left side of a parent Canvas. The default value is NaN.

    And in the remarks it said that this properity does not affect the size of parent Canvas as the Bottom and Right property will be adjusted accordingly.

     Therefore it definately moving the entire canvas.

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified
  • User profile image
    MasterPi

    , cheong wrote

    And in the remarks it said that this properity does not affect the size of parent Canvas as the Bottom and Right property will be adjusted accordingly.

     Therefore it definately moving the entire canvas.

    If you're suggesting that children can somehow push their parent canvas if they go past the initial boundary, then that's not the case. A canvas' size stays fixed while children will float freely outside the canvas' boundary, unless you specify clipping.

  • User profile image
    figuerres

    in a window the canvas works with the two lines

    <Canvas Background="#FFE217A3" Width="200" Height="100">
    <Line Stroke="Black" X1="5" Y1="5" X2="100" Y2="5"/>
    <Line Stroke="Blue" X1="5" Y1="5" X2="100" Y2="5" Canvas.Top="5" />
    </Canvas>

    so I suspect the brush has something to do with how it is working.

  • User profile image
    MasterPi

    @figuerres: Yeah, I think the telerik control I'm applying the brush to masks the brush, so only a line representation of the underlying brush is visible. At a very high stroke thickness and at a perfectly right angle, you can see the two distinct lines. The moment you change the orientation of the telerik connection, the lines looks mixed together (as if the underlying lines didn't move).

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.