user626528
user626528

Reputation: 14417

Please explain, how this style works?

        <Style TargetType="DataGridCell">
            <Style.Setters>
                <Setter Property="TextBlock.VerticalAlignment" Value="Center" />
                <Setter Property="TextBlock.FontSize" Value="30" />
                <Setter Property="Image.Width" Value="24" />
            </Style.Setters>
        </Style>

The first 2 setters work as expected. The last setter applies width to all elements, images and text blocks too. Why?

Upvotes: 0

Views: 118

Answers (1)

Kent Boogaart
Kent Boogaart

Reputation: 178770

That's because Image.Width refers to the FrameworkElement.Width property via the Image class. In other words, you're resolving the FrameworkElement.WidthProperty field by by way of the Image class, which inherits it from FrameworkElement.

If you want the width only to apply to images, use a separate style that with a TargetType of Image.

Upvotes: 4

Related Questions