开发者

Global implicit syle on the type Control in WPF

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜