在App.xaml文件中添加 xmlns:c4f="clr-namespace:Coding4Fun.Toolkit.Controls;assembly=Coding4Fun.Toolkit.Controls" <!--应用程序资源--> <Application.Resources> <ControlTemplate x:Key="MsgPropmtNoBorder" TargetType="c4f:MessagePrompt"> <Grid VerticalAlignment="Stretch"> <Rectangle Fill="{StaticResource TransparentBrush}"/> <Border VerticalAlignment="Top" Margin="10" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="5" CornerRadius="10"> <StackPanel Margin="10"> <TextBlock Text="{TemplateBinding Title}" Margin="0,-10,-25,10" FontSize="30" TextWrapping="Wrap" FontFamily="Segoe WP Light"/> <ContentPresenter Content="{TemplateBinding Body}"/> <StackPanel Margin="0,10,0,0" Name="actionButtonArea" Orientation="Horizontal" HorizontalAlignment="Center"/> </StackPanel> </Border> </Grid> </ControlTemplate> </Application.Resources>
后台添加: MessagePrompt textBoxMsgPrompt = new MessagePrompt(); textBoxMsgPrompt.Template = Application.Current.Resources["MsgPropmtNoBorder"] as ControlTemplate;