我正在制作一个可通过自定义"下一步"和"后退"按钮和命令(即不使用a NavigationWindow)导航的WPF应用程序.在一个屏幕上,我有一个ListBox必须支持多个选择(使用Extended模式).我有一个该屏幕的视图模型,并将所选项目存储为属性,因为它们需要维护.
但是,我知道SelectedItemsa 的属性ListBox是只读的.我一直在尝试使用此解决方案解决此问题,但我无法将其应用到我的实现中.我发现无法区分何时取消选择一个或多个元素以及何时在屏幕之间导航(NotifyCollectionChangedAction.Remove在两种情况下都会引发,因为从技术上讲,所有选定的项目在远离屏幕时都会被取消选择).我的导航命令位于一个单独的视图模型中,该模型管理每个屏幕的视图模型,因此我不能将任何与视图模型相关的实现与其中相关联ListBox.
我发现了其他一些不太优雅的解决方案,但这些解决方案似乎都没有强制实现视图模型和视图之间的双向绑定.
任何帮助将不胜感激.我可以提供一些我的源代码,如果它有助于理解我的问题.
我正在实现一个 WPF 应用程序,该应用程序为字典中给出的每个键/值对执行 PowerShell 脚本,使用该对作为脚本参数。我将脚本的每次运行存储为管道中的新命令。但是,当我在每次运行脚本后需要输出时,这会导致我只从上次运行的命令中获取输出。我曾考虑在每次执行脚本时创建一个新管道,但我需要知道脚本的所有执行何时完成。这是帮助解释我的问题的相关代码:
private void executePowerShellScript(String scriptText, Dictionary<String, String> args)
{
// Create the PowerShell object.
PowerShell powerShell = PowerShell.Create();
// If arguments were given, add the script and its arguments.
if (args != null)
{
foreach (KeyValuePair<String, String> arg in args)
{
powerShell.AddScript(scriptText);
powerShell.AddArgument(arg.Key);
powerShell.AddArgument(arg.Value);
}
}
// Otherwise, just add the script.
else
powerShell.AddScript(scriptText);
// Add the event handlers.
PSDataCollection<PSObject> output = new PSDataCollection<PSObject>();
output.DataAdded += new EventHandler<DataAddedEventArgs>(Output_DataAdded);
powerShell.InvocationStateChanged +=
new EventHandler<PSInvocationStateChangedEventArgs>(Powershell_InvocationStateChanged);
// Invoke the pipeline …Run Code Online (Sandbox Code Playgroud)