XAML样式属性没有被继承

时间:2019-05-12 16:58:50

标签: c# wpf xaml wpf-controls .net-4.6

我为定位按钮的超链接做了一个简单的样式:

<Style x:Key="Hyperlink" TargetType="{x:Type Button}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="Foreground" Value="{StaticResource ForegroundDarkBrush}" />

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <TextBlock x:Name="innerText" Text="{TemplateBinding Content}" />

                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Foreground" Value="{StaticResource AppDarkBlueBrush}" />
                        <Setter TargetName="innerText" Property="TextDecorations" Value="Underline" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

我的问题是,当应用于设置了FontSizeFontWeightFontFamily之类的某些属性的按钮控件时,它们将被忽略并且不起作用:

<Button
    Command="{Binding OpenCommand}"
    Content="Open"
    FontSize="20"
    Style="{StaticResource Hyperlink}" />

如何在样式模板中使TextBlock继承此类属性?

编辑

忘记了我提到的FontSize之类的属性实际上可以工作,但仅在设计模式下有效。

1 个答案:

答案 0 :(得分:1)

您可以指示您希望文本块从“按钮”“继承”某些属性,如下所示:

def saveResults(a,b):        
    preds_test = a.predict(b, verbose=1)
    cutoff=0.5
    a = 'C:/Users/ultim\Desktop/Rest/testpredict'
    for i in range(len(preds_test)):
        lab_img = label(preds_test[i] > cutoff)
        for i in range(1, lab_img.max() + 1):
            lab_img[i] = np.array(lab_img[i], dtype=np.uint8)
            cv2.imwrite('a' + i, lab_img[i])
saveResults(modelZ,X_test)