日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

WPF自定義一個(gè)MessageBox

 xyjackxjw 2013-05-16

WPF自定義一個(gè)MessageBox

WPF的MessageBox太丑了,自己定義了一個(gè)。

這是效果:

 

XAML:

復(fù)制代碼
<Window x:Class="AgileToDo.UMessageBox"
        xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
        Title
="UMessageBox" Height="130" Width="280" WindowStyle="None"   Background="{x:Null}"  
        ResizeMode
="NoResize"  x:Name="main"
        AllowsTransparency
="True" WindowStartupLocation="CenterScreen">
    <Window.Triggers>
        <EventTrigger RoutedEvent="Window.Loaded" >
            <BeginStoryboard>
                <Storyboard Name="sbOpShow">
                    <DoubleAnimation
                    
Storyboard.TargetName="main" 
                    Storyboard.TargetProperty
="Opacity" 
                    From
="0" To="0.8" Duration="0:0:0.15"/>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Window.Triggers>
    <Window.Resources>
    </Window.Resources>

    <Border Background="#F03A3A3A" Opacity="1" CornerRadius="3">
            <Canvas>
                
            <Border Canvas.Top="0" Height="25" Width="{Binding ElementName=main, Path=Width,UpdateSourceTrigger=PropertyChanged}" 
                    BorderThickness
="0,0,0,1" BorderBrush="#FFEFE2E2">
                <TextBlock x:Name="lblTitle" Text="test" HorizontalAlignment="Left" 
                           Foreground
="#FFCBBEBE" FontSize="14"
                           VerticalAlignment
="Center" Margin="5"/>
            </Border>
            <TextBlock x:Name="lblMsg"
                       Foreground
="White" FontSize="14" 
                       TextWrapping
="Wrap" Text="test"
                       HorizontalAlignment
="Center" Canvas.Left="20"
                       Canvas.Top
="50" 
                       
/>
            <Border BorderBrush="#FF60C1C1" BorderThickness="0.5" Height="22" 
                    Canvas.Bottom
="10" Canvas.Right="85" MouseLeftButtonDown="Yes_MouseLeftButtonDown"
                 Name
="border1" Width="49" Background="#FFC7C7C7" CornerRadius="2">
                <TextBlock Text="YES"  HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
            <Border BorderBrush="#FF60C1C1" BorderThickness="0.5" Height="22" 
                    Canvas.Bottom
="10" Canvas.Right="30" MouseLeftButtonDown="No_MouseLeftButtonDown"
                Name
="border2" Width="49" CornerRadius="2" Background="#FFC7C7D1">
                <TextBlock Text="NO"  HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </Canvas>
    </Border>
</Window>
復(fù)制代碼

 CS:

復(fù)制代碼
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Animation;


namespace AgileToDo
{
    /// <summary>
    
/// UMessageBox.xaml 的交互邏輯
    
/// </summary>
    public partial class UMessageBox : Window
    {
        /// <summary>
        
/// 禁止在外部實(shí)例化
        
/// </summary>
        private UMessageBox()
        {
            InitializeComponent();
        }

        public new string Title
        {
            get { return this.lblTitle.Text; }
            set { this.lblTitle.Text = value; }
        }

        public string Message
        {
            get { return this.lblMsg.Text; }
            set { this.lblMsg.Text = value; }
        }

        /// <summary>
        
/// 靜態(tài)方法 模擬MESSAGEBOX.Show方法
        
/// </summary>
        
/// <param name="title">標(biāo)題</param>
        
/// <param name="msg">消息</param>
        
/// <returns></returns>
        public static bool? Show(string title,string msg)
        {
            var msgBox = new UMessageBox();
            msgBox.Title = title;
            msgBox.Message = msg;
            return msgBox.ShowDialog();
        }

        private void Yes_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }


        private void No_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }
    }
}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多