【问题标题】:The TargetType for Line in style doesn't work in UWPLine in style 的 TargetType 在 UWP 中不起作用
【发布时间】:2020-04-12 14:24:36
【问题描述】:

我有以下代码:

<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>

您可以看到屏幕截图,样式中的StrokeDashArray 属性值仅应用于第一行。为什么?

【问题讨论】:

    标签: uwp uwp-xaml


    【解决方案1】:

    我可以重现这个问题,但我不确定是什么导致了这种意外行为。我会向团队询问这个问题。作为一种解决方法,您可以使用 StaticResource 来共享 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>
    

    【讨论】:

    • 团队确认这是一个问题,并在 github 中解雇了一个问题,您可以跟踪它here
    猜你喜欢
    • 2011-05-15
    • 1970-01-01
    • 2018-09-30
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多