开发者

Please explain, how this style works?

开发者 https://www.devze.com 2023-02-20 05:28 出处:网络
<Style TargetType=\"DataGridCell\"> <Style.Setters> <Setter Property=\"TextBlock.VerticalAlignment\" Value=\"Center\" />
        <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

精彩评论

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