Modeless Form wait with code execution till button press
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have an ExternalApplication that calls an ExternalCommand. Somewhere during the execution of the command,
I have a very simple modeless form that is basically an "Apply" Button - it's supposed to let the user tell me when he has finished a certain action in the UI. The problem I'm facing is that I can't find a way to pause the execution of code until the user has pressed apply.
My own simple checkbox form has the following code.
CheckBoxForm.xaml.cs:
public partial class CheckBoxForm : Window
{
public bool isClosed { get; private set; }
public CheckBoxForm()
{
isClosed = false;
InitializeComponent();
}
private void CheckBoxTriggered(object sender, RoutedEventArgs e)
{
isClosed = true;
Close();
}
}
CheckBoxForm.xaml
<Window x:Class="RevitAPIHandler.UI.Forms.CheckBoxForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Apply" Height="140" Width="250" Topmost="True">
<StackPanel Margin="10">
<Label FontWeight="Bold">
<Label.Content>
<AccessText TextWrapping="Wrap" Text="Press here if you're done with your changes." />
</Label.Content>
</Label>
<CheckBox Checked="CheckBoxTriggered">Apply</CheckBox>
</StackPanel>
</Window>
Function that is called from a function of a function of my ExternalCommand. Note that the function still has access to the UIApplication, if that helps.
public void GetUserInput(UIApplication uiapp)
{
// some stuff happening here
// now my checkbox WPF form
_checkBoxForm = new CheckBoxForm();
_checkBoxForm.Show(); // this starts modeless. User should now do stuff in the UI, and, once finished, press the checkmark button.
// Other stuff happening here. BUT I want to wait with the execution of this stuff until the user has checked the checkbox in the modeless form
return;
}
I'm wondering whether there is a solution to my problem or whether I'm tackling the problem the wrong way. I've looked at the SDK Modeless samples with Idling and ExternalEventHandler as well as many posts in this forum, but all examples I find seem to incorporate the modeless form on the level of the ExternalApplication itself, whereas for me it's supposed to be a small step within a single command.