在 Revit 中关闭窗口 wpf



我必须单击按钮,保存更改并关闭窗口。

public BaseCommand SaveCommand => saveCommand ?? (saveCommand = new BaseCommand(SaveMetod, SaveCanMetod));
private bool SaveCanMetod() => IsSelectedCamera && (SelectedCamera.Height != CameraHeight || SelectedCamera.Width != CameraWidth);
        private void SaveMetod()
        {
            if (SaveCanMetod())
            {
                SelectedCamera.Width = CameraWidth.Value;
                SelectedCamera.Height = CameraHeight.Value;                
                //Application.Current.MainWindow.Close();
            }
        }

字符串"Application.Current.MainWindow.Close((;"在Revit上启动应用程序时不起作用。

请参阅此示例。

在 XAML 中:

<Window Name="ThisWindow">
.
.
.
<Button Command="{Binding SaveCommand}" CommandParameter="{Binding ElementName=ThisWindow}" />

在代码隐藏中:

private void SaveMethod(object paramter)
{
    var currentWindow = (Window)paramter;
    // TODO: ...
    currentWindow.Close();
}

和命令:

public class RelayCommand : ICommand    
{    
    private Action<object> execute;    
    private Func<object, bool> canExecute;    
    public event EventHandler CanExecuteChanged    
    {    
        add { CommandManager.RequerySuggested += value; }    
        remove { CommandManager.RequerySuggested -= value; }    
    }    
    public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)    
    {    
        this.execute = execute;    
        this.canExecute = canExecute;    
    }    
    public bool CanExecute(object parameter)    
    {    
        return this.canExecute == null || this.canExecute(parameter);    
    }    
    public void Execute(object parameter)    
    {    
        this.execute(parameter);    
    }    
}  

最新更新