WPF 统一窗体样式(示例用户控件Prism框架中)

实现效果能将将程序中的弹窗的窗体,写上统一样式,作用在用户控件上(用户控件在程序中担当的就是弹窗)实现效果如图 当前是指定所有的弹窗都为此样式外观

使程序为统一的样式 更加的规范统一 美观 

样式的style 源码为 (资源字典中记得添加)

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="MessageWindowStyle" TargetType="Window">
        <Setter Property="AllowsTransparency" Value="True" />
        <Setter Property="ResizeMode" Value="NoResize" />
        <Setter Property="SizeToContent" Value="WidthAndHeight" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Window}">
                    <Border
                        Margin="5,5,5,10"
	                        Background="{ TemplateBinding Background  }"
	                        BorderBrush="{TemplateBinding BorderBrush}"
	                        BorderThickness="1">
                        <Border.Effect>
                            <DropShadowEffect
	                                BlurRadius="10"
	                                Direction="1"
	                                Opacity="0.5"
	                                ShadowDepth="0.5"
	                                Color="Black" />
                        </Border.Effect>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="30" />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Border Grid.Row="0" Background="Red">
                                <Grid Margin="5,0">
                                    <TextBlock
	                                        HorizontalAlignment="Left"
	                                        VerticalAlignment="Center"
	                                        FontSize="16"
	                                        FontWeight="Medium"
	                                        Foreground="White"
	                                        Text="{Binding Title}" />

                                    <Button
	                                        HorizontalAlignment="Right"
	                                        VerticalAlignment="Center"
	                                        Content="关闭"
	                                        IsCancel="True"
	                                        Tag="IsCloseButton" />
                                </Grid>
                            </Border>
                            <ContentPresenter Grid.Row="1" />
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="UseLayoutRounding" Value="True" />
        <Setter Property="WindowStyle" Value="None" />
    </Style>
</ResourceDictionary>

在被弹出的用户控件上引用

<UserControl x:Class="WPfPrism.Dryloc.View.ViewC"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WPfPrism.Dryloc.View"
    xmlns:prism="http://prismlibrary.com/"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <prism:Dialog.WindowStyle>
        <Style BasedOn="{StaticResource MessageWindowStyle}" TargetType="Window" />
    </prism:Dialog.WindowStyle>
    <Grid>
        <TextBlock Text="View C" FontSize="80"/>

    </Grid>
</UserControl>

如果有疑问可以 私信我! 

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

学软件开发的猪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值