写自己的WPF样式 - 窗体

初试WPF样式,感觉还不错。上篇写完了按钮的样式下面写窗体,废话不多说直接上代码:

(1)定义一个窗体样式"MyWpfWindow"

<Style x:Key="MyWpfWindow" TargetType="{x:Type Window}">
            <Setter Property="AllowsTransparency" Value="true"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="ResizeMode" Value="NoResize"/>
            <Setter Property="WindowStyle" Value="None"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Window}">
                        <Grid Margin="10">
                            <Rectangle Fill="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"  
                              RadiusX="5" RadiusY="5">
                                <Rectangle.Effect>
                                    <DropShadowEffect BlurRadius="10" ShadowDepth="0"/>
                                    
                                </Rectangle.Effect>
                            </Rectangle>
                            <Border 
                                Background="{TemplateBinding Background}"  
                                BorderBrush="{TemplateBinding BorderBrush}"  
                                BorderThickness="{TemplateBinding BorderThickness}"  
                                Padding="{TemplateBinding Margin}"  
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"  
                                CornerRadius="5">
                                <ContentPresenter />
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

下面看效果:

posted @ 2015-03-26 10:58  CharlesShang  阅读(1007)  评论(0编辑  收藏  举报