【问题标题】:Why the following WPF style is not applied?为什么不应用以下 WPF 样式?
【发布时间】:2010-11-22 23:45:43
【问题描述】:

为什么以下样式不起作用?我在其他地方有完全相同的构造,但控件不同,并且可以正常工作。

使用TargetType="{x:Type Separator}" 代替TargetType="Separator" 也不起作用。既不会在 XAML 层次结构中移动 Style 上层。我可以避免使用x:Key="styleName"Style="{StaticResource styleName}" 吗?

但更重要的是,我试图理解为什么这种样式绑定并不总是有效。

<ToolBar Height="25">
    <ToolBar.Resources>
        <Style TargetType="Separator">
            <Setter Property="Margin" Value="15"/>
        </Style>
        <Style TargetType="RadioButton">
            <Setter Property="Margin" Value="10"/>
            <Setter Property="Width" Value="50"/>
        </Style>
    </ToolBar.Resources>

    <RadioButton Content="A"/>  <!-- NOT APPLIED HERE -->
    <Separator/>                <!-- NOT APPLIED HERE -->
    <RadioButton Content="B"/>  <!-- NOT APPLIED HERE -->
</ToolBar>

【问题讨论】:

    标签: wpf binding styles


    【解决方案1】:

    WPF 的工具栏用它的子控件做了一些时髦的事情。与其他容器不同,它并不像定义适用于类型的样式那么简单。

    查看这篇博文,了解一些可能有帮助的信息。 Styling controls on a ToolBar.

    【讨论】:

    • 工具栏上的优秀文章。感谢您的链接!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-11
    • 2020-02-15
    • 2017-10-02
    相关资源
    最近更新 更多