c# - Windows 8 消息框样式 WPF

标签 c# css wpf

我正在尝试在 WPF 中创建 WIN8 Msgbox Style 并按照此操作 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

最佳答案

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

private readonly IWindowManager _windowManager;

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

关于c# - Windows 8 消息框样式 WPF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18629232/

相关文章:

c# - 获取 WPF TreeView 中可见元素的列表

c# - 有什么方法可以查看 C# 应用程序的泄漏内存?

c# - ItemsControl 不显示我的项目

c# - C# 编译器的优化程度如何?

C# selenium 对远程 Web 驱动程序服务器的 URL 的 HTTP 请求在 60 秒后超时

c# - 中位数 c# 错误计算

css - 为什么我们使用响应式方法,而 % 属性使我们的页面适应任何屏幕尺寸?

html - 溢出 :hidden not working on my div

c# - 使用 AngularJs 从数据库中检索和过滤数据

css - DIV 中的图像 - 垂直居中