实现效果能将将程序中的弹窗的窗体,写上统一样式,作用在用户控件上(用户控件在程序中担当的就是弹窗)实现效果如图 当前是指定所有的弹窗都为此样式外观
使程序为统一的样式 更加的规范统一 美观
样式的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>
如果有疑问可以 私信我!