正确退出 Revit 的 wpf 插件
Properly exit a wpf plugin for Revit
我正在为 Revit 开发一个插件。 Revit 只允许 dll 类型的插件,我为 gui 选择了 c# 和 wpf。我无法在本地初始化 wpf,所以我需要将它作为内容包含在 system.windows.window 中。
现在,如果我用右上角的 X 程序继续关闭 window(循环处理等),它不会终止。 Window.close() 再次只是关闭 window 而不是它自己的应用程序。
我应该如何退出我的应用程序而不让它潜伏在阴影中?
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class FDNMain : IExternalCommand
{
public Result Execute(ExternalCommandData CommandData, ref string message, ElementSet elements)
{
FDNControl wpfControl = new FDNControl();
return Result.Succeeded;
}
}
以上是无法初始化(显示)wpfControl 的 Revit 外部命令 class。所以我需要用 System.Windows.Window 包装 wpfcontrol 如下:
Window hostWindow = new Window();
hostWindow.Content = wpfControl;
hostWindow.Show();
好的,我明白了。 Visual Studio 中没有 XAML Window 模板用于 class 库,但您可以像以前一样创建一个 UserControl,然后更改 UserControl
中的标签XAML 到 Window
一个。
您还需要在 .xaml.cs 中更改它(您也可以将其删除,因为它是部分 class 并且父 class 与 XAML).之后,您就可以在 window.
上调用 ShowDialog
我定义了全局静态变量,它在主机 window 关闭时设置为 true。并在 while 语句中设置要检查的条件,以便继续循环。如:
...
Global.hostWindow.Closing += hostWindow_Closing;
...
private void hostWindow_Closing(object sender, EventArgs e)
{
Global.Closing = true;
}
...
while (Nodes.Count > 0 && Global.Closing == false)
{
...
}
我正在为 Revit 开发一个插件。 Revit 只允许 dll 类型的插件,我为 gui 选择了 c# 和 wpf。我无法在本地初始化 wpf,所以我需要将它作为内容包含在 system.windows.window 中。 现在,如果我用右上角的 X 程序继续关闭 window(循环处理等),它不会终止。 Window.close() 再次只是关闭 window 而不是它自己的应用程序。 我应该如何退出我的应用程序而不让它潜伏在阴影中?
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class FDNMain : IExternalCommand
{
public Result Execute(ExternalCommandData CommandData, ref string message, ElementSet elements)
{
FDNControl wpfControl = new FDNControl();
return Result.Succeeded;
}
}
以上是无法初始化(显示)wpfControl 的 Revit 外部命令 class。所以我需要用 System.Windows.Window 包装 wpfcontrol 如下:
Window hostWindow = new Window();
hostWindow.Content = wpfControl;
hostWindow.Show();
好的,我明白了。 Visual Studio 中没有 XAML Window 模板用于 class 库,但您可以像以前一样创建一个 UserControl,然后更改 UserControl
中的标签XAML 到 Window
一个。
您还需要在 .xaml.cs 中更改它(您也可以将其删除,因为它是部分 class 并且父 class 与 XAML).之后,您就可以在 window.
上调用ShowDialog
我定义了全局静态变量,它在主机 window 关闭时设置为 true。并在 while 语句中设置要检查的条件,以便继续循环。如:
...
Global.hostWindow.Closing += hostWindow_Closing;
...
private void hostWindow_Closing(object sender, EventArgs e)
{
Global.Closing = true;
}
...
while (Nodes.Count > 0 && Global.Closing == false)
{
...
}