我正在使用MV-VM模式
在我的VM中,我有类似的代码
public class ViewModel {
public XmlDocument Document { ... }
....
}
Run Code Online (Sandbox Code Playgroud)
我有一个标记扩展,我想使用该文档
public override object ProvideValue(IServiceProvider serviceProvider) {
IProvideValueTarget valueProvider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
if (valueProvider != null) {
DependencyObject target = valueProvider.TargetObject as DependencyObject;
XmlDocument doc = Foo.GetDocument(target);
if (doc != null) {
var n = doc.SelectSingleNode("/.../text()");
if (n != null) return n.Value;
}
}
return "«" + ObjectProperty + "»";
}
Run Code Online (Sandbox Code Playgroud)
我创建了附加属性Foo.Document,并将其附加到我的页面(页面的DataContext设置为我的ViewModel类的实例)
<Page ... lc:Foo.Document="{Binding Document}">
...
</Page>
Run Code Online (Sandbox Code Playgroud)
(为了不必在每次使用标记扩展时都将其作为参数键入)
现在,在我的标记扩展中,当我尝试读取Document附加属性时,我总是得到一个空文档.通过调试绑定,它看起来像一个计时问题,因为附加属性在运行标记扩展后获得适当的值.
有可能以某种方式让这个工作?
我想使用 shell 可执行文件来尊重要启动的应用程序的用户首选项,但我还需要知道该特定应用程序何时关闭。
Process editProcess = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = filename;
startInfo.Verb = "edit";
startInfo.UseShellExecute = true;
editProcess.StartInfo = startInfo;
// start the default editor
editProcess.Start();
editProcess.WaitForExit();
Run Code Online (Sandbox Code Playgroud)
WaitForExit 似乎在 shell 进程退出时返回,而不是在真实进程退出时返回。
有没有比手动解析注册表、找到正确的应用程序来启动并显式启动该应用程序而不执行 shell 更好的方法来了解启动的应用程序何时退出?