在 Revit 中关闭 window wpf
Close window wpf in Revit
我必须单击按钮,保存更改并关闭 window。
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();
}
}
当我在 revit 上启动我的应用程序时,字符串 "Application.Current.MainWindow.Close();" 不起作用。
看这个例子。
在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);
}
}
我必须单击按钮,保存更改并关闭 window。
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();
}
}
当我在 revit 上启动我的应用程序时,字符串 "Application.Current.MainWindow.Close();" 不起作用。
看这个例子。
在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);
}
}