Windows 8消息框样式WPF

时间:2013-09-05 06:30:24

标签: c# css wpf

我正在尝试在WPF中创建WIN8 Msgbox样式并按照此操作 tuts。问题是从主窗口调用的消息框。 如果我想按下按钮时出现消息框,请帮助我 从儿童窗口?

这是我的主窗口的ViewModel

using FirstFloor.ModernUI.Presentation;
using dLondre;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using dLondre.Models;
using dLondre.ViewModels;
using System.Windows;
using Caliburn.Micro;
using dLondre.Interfaces;

namespace dLondre.ViewModels
{
    [Export(typeof(IShell))]
    public class MainWindowViewModel : Screen, IShell
    {
        private readonly IWindowManager _windowManager;

        private int _overlayDependencies;

        [ImportingConstructor]
        public MainWindowViewModel(IWindowManager windowManager)
        {
            _windowManager = windowManager;
        }

        public bool IsOverlayVisible
        {
            get { return _overlayDependencies > 0; }
        }

        public void ShowOverlay()
        {
            _overlayDependencies++;
            NotifyOfPropertyChange(() => IsOverlayVisible);
        }

        public void HideOverlay()
        {
            _overlayDependencies--;
            NotifyOfPropertyChange(() => IsOverlayVisible);
        }

        // I want to do this in the child window
        //               |
        //               |
        //               v
        public void DisplayMessageBox()
        {
           MessageBoxResult dix;
           dix = _windowManager.ShowMetroMessageBox("message", "title", MessageBoxButton.OKCancel);
           if (dix == MessageBoxResult.OK)
           {
               _windowManager.ShowMetroMessageBox("OK");
           }
           else
           {
               _windowManager.ShowMetroMessageBox("CANCEL");
           }
        }        

    }
}

这是我儿童窗口的ViewModels

using FirstFloor.ModernUI.Presentation;
using dLondre;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using dLondre.Models;
using dLondre.ViewModels;
using System.Windows;
using Caliburn.Micro;

namespace dLondre.ViewModels {
    public class UserViewModel : NotifyPropertyChanged, IDataErrorInfo
    {
        #region Construction
        public UserViewModel()
        {
            _user = new User { FirstName = "",
                               LastName="",
                               Gender = "",
                               BirthDate= DateTime.Today,
                               Address="",
                               City="",
                               ZipCode="",
                               Email="",
                               UserID="",
                               Password="",
                               Status="",
                               Deleted=false,
                               CreatedOn=DateTime.Today,
                               CreatedBy="",
                               UpdatedOn=DateTime.Today,
                               UpdatedBy="" };
        }
        #endregion

        #region Members
        User _user;
        #endregion

        #region Properties
        public User User 
        {
            get
            {
                return _user;
            }
            set
            {
                _user = value;
            }
        }

        public string FirstName
        {
            get { return User.FirstName; }
            set
            {
                if (User.FirstName != value)
                {
                    User.FirstName = value;
                    OnPropertyChanged("FirstName");
                }
            }
        }

        public string LastName
        {
            get { return User.LastName; }
            set
            {
                if (User.LastName != value)
                {
                    User.LastName = value;
                    OnPropertyChanged("LastName");
                }
            }
        }

        public string Gender
        {
            get { return User.Gender; }
            set
            {
                if (User.Gender != value)
                {
                    User.Gender = value;
                    OnPropertyChanged("Gender");
                }
            }
        }

        public DateTime BirthDate
        {
            get { return User.BirthDate; }
            set
            {
                if (User.BirthDate != value)
                {
                    User.BirthDate = value;
                    OnPropertyChanged("BirthDate");
                }
            }
        }

        public string Address
        {
            get { return User.Address; }
            set
            {
                if (User.Address != value)
                {
                    User.Address = value;
                    OnPropertyChanged("Address");
                }
            }
        }

        public string City
        {
            get { return User.City; }
            set
            {
                if (User.City != value)
                {
                    User.City = value;
                    OnPropertyChanged("City");
                }
            }
        }

        public string ZipCode
        {
            get { return User.ZipCode; }
            set
            {
                if (User.ZipCode != value)
                {
                    User.ZipCode = value;
                    OnPropertyChanged("ZipCode");
                }
            }
        }

        public string Email
        {
            get { return User.Email; }
            set
            {
                if (User.Email != value)
                {
                    User.Email = value;
                    OnPropertyChanged("Email");
                }
            }            
        }

        public string UserId
        {
            get { return User.UserID; }
            set
            {
                if (User.UserID != value)
                {
                    User.UserID = value;
                    OnPropertyChanged("UserId");
                }
            }
        }

        public string Password
        {
            get { return User.Password; }
            set
            {
                if (User.Password != value)
                {
                    User.Password = value;
                    OnPropertyChanged("Password");
                }
            }
        }

        public string Status
        {
            get { return User.Status; }
            set
            {
                if (User.Status != value)
                {
                    User.Status = value;
                    OnPropertyChanged("Status");
                }
            }
        }

        public bool Deleted
        {
            get { return User.Deleted; }
            set
            {
                if (User.Deleted != value)
                {
                    User.Deleted = value;
                    OnPropertyChanged("Deleted");
                }
            }
        }

        public DateTime CreatedOn
        {
            get { return User.CreatedOn; }
            set
            {
                if (User.CreatedOn != value)
                {
                    User.CreatedOn = value;
                    OnPropertyChanged("CreatedOn");
                }
            }
        }

        public string CreatedBy
        {
            get { return User.CreatedBy; }
            set
            {
                if (User.CreatedBy != value)
                {
                    User.CreatedBy = value;
                    OnPropertyChanged("CreatedBy");
                }
            }
        }

        public DateTime UpdatedOn
        {
            get { return User.UpdatedOn; }
            set
            {
                if (User.UpdatedOn != value)
                {
                    User.UpdatedOn = value;
                    OnPropertyChanged("CreatedOn");
                }
            }
        }

        public string UpdatedBy
        {
            get { return User.UpdatedBy; }
            set
            {
                if (User.UpdatedBy != value)
                {
                    User.UpdatedBy = value;
                    OnPropertyChanged("UpdatedBy");
                }
            }
        }
        #endregion

        public string Error
        {
            get { return null; }
        }

        public string this[string columnName]
        {
            get
            {
                if (columnName == "FirstName")
                {
                    return string.IsNullOrEmpty(User.FirstName) ? "Required value" : null;
                }
                if (columnName == "LastName")
                {
                    return string.IsNullOrEmpty(User.LastName) ? "Required value" : null;
                }
                if  (columnName == "Email")
                {
                    return string.IsNullOrEmpty(User.Email) ? "Required value" : null;
                }
                if (columnName == "UserId")
                {
                    return string.IsNullOrEmpty(User.UserID) ? "Required value" : null;
                }
                return null;
            }
        }

        private readonly IWindowManager _windowManager;
        // Here comes the trouble
        //               |
        //               |
        //               v
        public void DisplayMessageBox()
        {
            _windowManager.ShowMetroMessageBox("Are you sure you want to delete...", "Confirm Delete",
                                               MessageBoxButton.YesNo);
        }

    }
}

这是我的sampleproject

1 个答案:

答案 0 :(得分:0)

当然,如果您将以下代码复制到子视图模型中,那么您可以从那里调用它吗?

private readonly IWindowManager _windowManager;

public void DisplayMessageBox()
{
    _windowManager.ShowMetroMessageBox("Are you sure you want to delete...", "Confirm 
Delete", MessageBoxButton.YesNo);
}