WPF:未应用样式

发布于 2024-09-24 10:41:14 字数 1146 浏览 0 评论 0原文

我有一个设置,比如

<ribbon:RibbonGallery>
    <ribbon:RibbonGallery.Resources>
        <Style TargetType="ribbon:RibbonGalleryItem">
            <Setter Property="Width" Value="24" />
            <Setter Property="Padding" Value="0" />
        </Style>
        <Style TargetType="Rectangle">
            <Setter Property="Width" Value="16" />
            <Setter Property="Height" Value="16" />
        </Style>
    </ribbon:RibbonGallery.Resources>

    </ribbon:RibbonGalleryCategory>
    <ribbon:RibbonGalleryCategory x:Name="themeColors" Header="Theme Colors" MinColumnCount="10" MaxColumnCount="10">
        <ribbon:RibbonGalleryCategory.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal" >
                    <Rectangle Fill="{Binding}" />
                </StackPanel>
            </DataTemplate>
        </ribbon:RibbonGalleryCategory.ItemTemplate>
    </ribbon:RibbonGalleryCategory>
</ribbon:RibbonGallery>

我的宽度和高度不应用于矩形。我想知道怎么了

i have a setup like

<ribbon:RibbonGallery>
    <ribbon:RibbonGallery.Resources>
        <Style TargetType="ribbon:RibbonGalleryItem">
            <Setter Property="Width" Value="24" />
            <Setter Property="Padding" Value="0" />
        </Style>
        <Style TargetType="Rectangle">
            <Setter Property="Width" Value="16" />
            <Setter Property="Height" Value="16" />
        </Style>
    </ribbon:RibbonGallery.Resources>

    </ribbon:RibbonGalleryCategory>
    <ribbon:RibbonGalleryCategory x:Name="themeColors" Header="Theme Colors" MinColumnCount="10" MaxColumnCount="10">
        <ribbon:RibbonGalleryCategory.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal" >
                    <Rectangle Fill="{Binding}" />
                </StackPanel>
            </DataTemplate>
        </ribbon:RibbonGalleryCategory.ItemTemplate>
    </ribbon:RibbonGalleryCategory>
</ribbon:RibbonGallery>

my width and height are not applied to the rectangles. i wondering whats wrong

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明月松间行 2024-10-01 10:41:14

您需要为您的样式提供一个Key,然后在代码中引用该键:

    <Style x:Key="RectStyle">
        <Setter Property="Width" Value="16" />
        <Setter Property="Height" Value="16" />
    </Style>

然后:

            <StackPanel Orientation="Horizontal" >
                <Rectangle Fill="{Binding}" Style="{StaticResource RectStyle}" />
            </StackPanel>

要使样式应用于您需要定义的类型的所有元素像这样:

<Style TargetType="{x:Type Rectangle}">

如果您想要一个元素有多种样式并选择要应用的样式,请使用前者。

来源

You need to give your style a Key and then reference that key in your code:

    <Style x:Key="RectStyle">
        <Setter Property="Width" Value="16" />
        <Setter Property="Height" Value="16" />
    </Style>

Then:

            <StackPanel Orientation="Horizontal" >
                <Rectangle Fill="{Binding}" Style="{StaticResource RectStyle}" />
            </StackPanel>

To get the style to apply to all elements of a type you need to define it like this:

<Style TargetType="{x:Type Rectangle}">

Use the former if you want to have several styles for an element and choose which one you want to apply.

Source

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文