开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜