WPF弹窗框自定义弹窗可调整样式直接使用

本文介绍如何在WPF中创建并自定义弹窗框的样式,通过实例展示了一个弹窗的最终效果,并提供了联系方式以获取具体代码示例。

下面是弹窗效果图
在这里插入图片描述

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WPF.DazzleUI2.Controls;

namespace DialogEx.MessageBoxEx
{
    /// <summary>
    /// 无边框消息对话框
    /// </summary>
    public partial class MessageBoxExWindow : DazzleWindow
    {
        public MessageBoxExResult Result { get; set; }
        public MessageBoxExWindow()
        {
            InitializeComponent();
        }
        //关闭
        private void ButtonClose_Click(object sender, RoutedEventArgs e)
        {
            Result = MessageBoxExResult.Cancel;
            this.Close();
        }
        //按钮事件
        private void ItemsControl_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (e.OriginalSource.GetType() == typeof(Button))
            {
                FrameworkElement btn = (FrameworkElement)e.OriginalSource;
                if (btn.Tag != null && btn.Tag.GetType() == typeof(MessageBoxExResult))
                {
                   this.Result = (MessageBoxExResult)btn.Tag;
                   this.Close();
                }
            }
        }

        private void DazzleWindow_Loaded(object sender, RoutedEventArgs e)
        {
            
        } 
    }
}


```xml
<dui:DazzleWindow x:Class="DialogEx.MessageBoxEx.MessageBoxExWindow"
        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:dui="clr-namespace:WPF.DazzleUI2.Controls;assembly=WPF.DazzleUI2"
        mc:Ignorable="d"
        xmlns:cvt="clr-namespace:DialogEx.Converters" 
        Title="DialogEx"
        ShowInTaskbar="False"
        WindowStartupLocation="CenterScreen"
        Width="330"
        Height="165"
        Loaded="DazzleWindow_Loaded"
        ResizeMode="NoResize"
        >
    <Window.Resources>
        <ResourceDictionary>
            <cvt:HiddenConverter x:Key="HiddenCvt"/>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/DialogEx;Component/Resource/App.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/DialogEx;Component/Resource/Style/QQ2015.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="33"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="33"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid Grid.Row="0" Background="{DynamicResource TipColor}">
            <Label Content="{Binding Title}" Foreground="{DynamicResource TipFontColor}" Height="25" HorizontalAlignment="Left" MinWidth="50" VerticalContentAlignment="Center" Margin="10,0,0,0"></Label>
            <Button Height="30" Width="30" Style="{DynamicResource BtnClose}" HorizontalAlignment="Right" Margin="0,-2,5,0" Click="ButtonClose_Click" ></Button>
        </Grid>
        <StackPanel Grid.Row="1" Margin="10,0,10,0" Background="{DynamicResource ContentColor}" Orientation="Horizontal">
            <Image Name="ImageContent" Width="50" Height="50" VerticalAlignment="Top" Margin="0,10,0,0" Visibility="{Binding ImageVisible,Converter={StaticResource HiddenCvt}}"  Source="{Binding ImageSource}">
            </Image>
            <TextBlock TextWrapping="Wrap" MaxWidth="250" Margin="5,15,0,0" Text="{Binding Content}" >
                <TextBlock.Style>
                    <Style TargetType="TextBlock">
                        <Setter Property="FontSize" Value="18" ></Setter> 
                    </Style>
                </TextBlock.Style>
            </TextBlock>
        </StackPanel>
        <Grid Grid.Row="2" Background="{DynamicResource BtnAreaColor}">
            <ItemsControl ItemsSource="{Binding BtnList}" Style="{DynamicResource ItemsListStyle}" PreviewMouseUp="ItemsControl_MouseUp">
                
            </ItemsControl>
        </Grid>
    </Grid>
</dui:DazzleWindow>

需直接要dome的联系 q q :1442601713

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

yangtianv

你的鼓励是我创作的动力

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

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

打赏作者

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

抵扣说明:

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

余额充值