The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps, Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
StrokeDashArray in a Style only applies to first Path RRS feed

  • Question

  • Reproduce:

    1. create a blank UWP application
    2. use the following XAML as the main page (see below).
    3. note that all 3 paths share the same style.
    4. run the app.
    5. observe that only the first path uses the StrokeDashArray (see below).

    Expected Outcome:  All 3 paths should have the same visual appearance.

    XAML for page:

    <Page
      x:Class="App1.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:App1"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d"
      Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.Resources>
    <Style x:Key="Line" TargetType="Path">
    <Setter Property="Stroke" Value="White"/>
    <Setter Property="StrokeDashArray" Value="3"/>
    </Style>
    </Page.Resources>
      <Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Black">
    <Path Canvas.Left="0" Canvas.Top="100" Style="{StaticResource Line}">
    <Path.Data>
    <LineGeometry StartPoint="0,0" EndPoint="1000,0"/>
    </Path.Data>
    </Path>
    <Path Canvas.Left="0" Canvas.Top="200" Style="{StaticResource Line}">
    <Path.Data>
    <LineGeometry StartPoint="0,0" EndPoint="1000,0"/>
    </Path.Data>
    </Path>
    <Path Canvas.Left="0" Canvas.Top="300"  Style="{StaticResource Line}">
    <Path.Data>
    <LineGeometry StartPoint="0,0" EndPoint="1000,0"/>
    </Path.Data>
    </Path>
    </Canvas>
    </Page>

    Visual Result of the above XAML note only first line "uses" the StrokeDashArray pattern (disallowed "until we are able to verify your account).  Note only the first line in document order uses the dashes, the other lines are solid.

    Sunday, October 20, 2019 3:57 PM

All replies

  • Hi,

    This might be caused by the StrokeDashArray property. It's not a DependencyProperty. So you could using StaticResource for sharing the value.

    Like this:

        <Page.Resources>
            <Style x:Key="Line" TargetType="Path">
                <Setter Property="Stroke" Value="White"/>
            </Style>
            <x:String x:Key="strokeArray">3</x:String>
        </Page.Resources>
        <Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Black">
            <Path Canvas.Left="0" Canvas.Top="100" Style="{StaticResource Line}" StrokeDashArray="{StaticResource strokeArray}">
                <Path.Data>
                    <LineGeometry StartPoint="0,0" EndPoint="1000,0"/>
                </Path.Data>
            </Path>
            <Path Canvas.Left="0" Canvas.Top="200" Style="{StaticResource Line}" StrokeDashArray="{StaticResource strokeArray}">
                <Path.Data>
                    <LineGeometry StartPoint="0,0" EndPoint="1000,0"/>
                </Path.Data>
            </Path>
            <Path Canvas.Left="0" Canvas.Top="300"  Style="{StaticResource Line}" StrokeDashArray="{StaticResource strokeArray}">
                <Path.Data>
                    <LineGeometry StartPoint="0,0" EndPoint="1000,0"/>
                </Path.Data>
            </Path>
        </Canvas>

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 21, 2019 1:53 AM
    Moderator