Docking window
An extension can display a docking window by providing a user control as its content and its view model.
Since dialog windows (modal or modeless) can be displayed using standard WPF features, no API support is provided for them.
The view model class for a user control must implement the interface IRCXUserControlViewModel.
internal partial class DockingWindowContentViewModel : IRCUserControlViewModel
{
/// <inheritdoc />
public string Id => Main.CommonId;
/// <inheritdoc />
public string ViewModelId => $"MyExtension.DockingWindow";
/// <inheritdoc />
public bool KeepOpenWhenProjectClosing => false;
/// <summary>
/// Captions
/// </summary>
public static IRCXCaptionGetter Captions { get; } = Main.Captions!;
/// <inheritdoc />
public RCXCaption WindowCaption { get; set; } = new(Main.CommonId, Caption.WindowTitle);
/// <inheritdoc />
public ImageSource? WindowIcon { get; set; } = Main.CommonIcon;
/// <inheritdoc />
public Task<bool> CloseAsync()
{
return Task.FromResult(true);
}
/// <inheritdoc />
public Task<bool> SaveAsync()
{
return Task.FromResult(true);
}
/// <inheritdoc />
public void Reload()
{
}
/// <inheritdoc />
public void Copy()
{
}
/// <inheritdoc />
public void Cut()
{
}
/// <inheritdoc />
public void Paste()
{
}
/// <inheritdoc />
public void SelectAll()
{
}
/// <inheritdoc />
public void Undo()
{
}
/// <inheritdoc />
public void Redo()
{
}
/// <inheritdoc />
public void ShowHelp()
{
}
/// <summary>
/// Show docking window
/// </summary>
/// <returns>Task</returns>
public static async Task Show()
{
DockingWindowContent control = new();
if (control.DataContext is DockingWindowContentViewModel controlViewModel)
{
await Main.GetAPI<IRCXWindowAPI>().ShowDockingWindowAsync(controlViewModel, control);
}
}
}
Editing commands (Copy, Cut, Paste, SelectAll, Undo, Redo) can be invoked by selecting the corresponding item in the edit menu of the main window.
To acquire or set the enable/disable status of each of these menu items, use the GetContentState or SetContentState method of the Window API, respectively.
An example of enabling Undo in the DockingWindowContentViewModel above is shown below.
var api = Main.GetAPI<IRCXWindowAPI>();
var state = api.GetContentState(this);
api.SetContentState(this, state | ContentState.CanUndo);
Pressing F10 when the window is displayed invokes the ShowHelp method.
An example of using ShowHelp to display the PDF manual held by the extension is shown below. (This example assumes that the PDF manual file is located in the Resources folder of your project. To include a file in an extension, in Visual Studio set the file property "Build Action" to "Content" and set "Copy to Output Directory" to "Copy always" or "Copy if newer."
public void ShowHelp()
{
try
{
var helpFilePath = Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!,
"Resources",
"Manual.pdf"
);
ProcessStartInfo processStartInfo = new()
{
FileName = helpFilePath,
UseShellExecute = true,
};
Process.Start(processStartInfo);
}
catch (Exception)
{
// Error handling
}
}