DevExpress DXWindow和Catel Castom窗口

时间:2013-07-16 13:51:36

标签: wpf devexpress catel

我正在尝试使用DevExpress DXWindow为Catel实现custom window,但是有一个问题,DXWindow没有完全支持这个接口。我想知道另一个可以实施变更通知吗? 附:抱歉我的英语不好。

public class DXWindowEx : DXWindow, IDataWindow
{
    private readonly WindowLogic logic;

    public DXWindowEx()
        : this(null)
    {
    }

    public DXWindowEx(IViewModel viewModel)
    {
        Type viewModelType = null;
        if (viewModel != null)
        {
            viewModelType = viewModel.GetType();
        }

        if (viewModelType == null)
        {
            var viewModelLocator = ServiceLocator.Default.ResolveType<IViewModelLocator>();
            viewModelType = viewModelLocator.ResolveViewModel(GetType());
            if (viewModelType == null)
            {
                const string error =
                    "The view model of the view could not be resolved. Use either the GetViewModelType() method or IViewModelLocator";
                throw new NotSupportedException(error);
            }
        }

        logic = new WindowLogic(this, viewModelType, viewModel);

        logic.ViewModelChanged += (sender, e) => ViewModelChanged.SafeInvoke(this, e);
        logic.ViewModelPropertyChanged += (sender, e) => ViewModelPropertyChanged.SafeInvoke(this, e);

        //This code did'n work
        //logic.PropertyChanged += (sender, e) => PropertyChanged(sender, e); 


        //PropertyChanged
        // Because the RadWindow does not close when DialogResult is set, the following code is required
        ViewModelChanged += (sender, e) => OnViewModelChanged();

        // Call manually the first time (for injected view models)
        OnViewModelChanged();

        WindowStartupLocation = WindowStartupLocation.CenterScreen;
        SetBinding(TitleProperty, new Binding("Title"));
    }


    public IViewModel ViewModel
    {
        get { return logic.ViewModel; }
    }

    public event EventHandler<EventArgs> ViewModelChanged;

    public event EventHandler<PropertyChangedEventArgs> ViewModelPropertyChanged;

    private void OnViewModelChanged()
    {
        if (ViewModel != null && !ViewModel.IsClosed)
        {
            ViewModel.Closed += ViewModelClosed;
        }
    }

    private void ViewModelClosed(object sender, ViewModelClosedEventArgs e)
    {
        Close();
    }
}

1 个答案:

答案 0 :(得分:1)

如果问题出在此处:

//This code did'n work
logic.PropertyChanged += (sender, e) => PropertyChanged(sender, e); 

然后解决方案是添加catel documentation for this situation中指定的PropertyChanged事件声明。

//...
logic.PropertyChanged += (sender, e) => PropertyChanged.SafeInvoke(this, e);
//...
public event EventHandler<PropertyChangedEventArgs> PropertyChanged;
//...

P.S。当我说DXWindow没有完全支持IDataWindow接口时,我不清楚你的意思是什么。由于缺乏有关确切问题的信息,很难确定问题的原因。请尽可能清楚地提出您的问题。