The TargetType for Line in style doesn't work in UWP

拟墨画扇 提交于 2021-02-11 13:38:11

问题


I have the following code:

<Grid>
    <Grid.Resources>
        <Style TargetType="Line">
            <Setter Property="Stroke" Value="Black"></Setter>
            <Setter Property="StrokeDashArray" Value="3"></Setter>
            <Setter Property="StrokeThickness" Value="3"></Setter>
        </Style>
    </Grid.Resources>
    <Line X1="20" X2="500" Y1="50" Y2="50"></Line>
    <Line X1="20" X2="500" Y1="100" Y2="100"></Line>
    <Line X1="20" X2="500" Y1="150" Y2="150"></Line>
</Grid>

You could see the screenshoot, the StrokeDashArray property value in the style only appled to the first line. Why?


回答1:


I could reproduce this issue, but I'm not sure what caused this unexpected behavior. I'll ask the team about this issue. As a workaround, you could use StaticResource for sharing the value of StrokeDashArray.

<Grid>
    <Grid.Resources>
        <Style TargetType="Line">
            <Setter Property="Stroke" Value="Black"></Setter>
            <Setter Property="StrokeThickness" Value="3"></Setter>
        </Style>
        <x:String x:Key="strokeArray">3</x:String>
    </Grid.Resources>
    <Line X1="20" X2="500" Y1="50" Y2="50" StrokeDashArray="{StaticResource strokeArray}"></Line>
    <Line X1="20" X2="500" Y1="100" Y2="100" StrokeDashArray="{StaticResource strokeArray}"></Line>
    <Line X1="20" X2="500" Y1="150" Y2="150" StrokeDashArray="{StaticResource strokeArray}"></Line>
</Grid>


来源:https://stackoverflow.com/questions/59419033/the-targettype-for-line-in-style-doesnt-work-in-uwp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!