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>
开发者_JAVA百科 </Style>
The first 2 setters work as expected. The last setter applies width to all elements, images and text blocks too. Why?
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
.
精彩评论