开发者

Global implicit syle on the type Control in WPF

开发者 https://www.devze.com 2023-03-23 05:55 出处:网络
This style should apply on every control, but it has no effect, WHY? <Style TargetType=\"{x:Type Control}\">

This style should apply on every control, but it has no effect, WHY?

<Style TargetType="{x:Type Control}">
            <Setter Property="Margin" Value="1" />      开发者_开发百科     
</Style>


Your statement is incorrect. Implicit Styles are only applied to the specified type, not to types that derive from it.

For example, assume you have a custom button like:

public class MyButton : Button {
    // ...
}

And an implicit Style like so:

<Style TargetType="{x:Type Button}">
    <Setter Property="Margin" Value="1" />           
</Style>

In the following XMAL, the Style above would not affect MyButton:

<Grid>
    <Button />
    <local:MyButton />
</Grid>
0

精彩评论

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