locked
Force property grid to write pending edits in code RRS feed

  • Question

  • Does anyone know if there is a way to force the WF 4 designer property grid to write a pending edit to a property through code?  The problem I'm having is that, in my rehosted designer, I have a toolbar with a save button, and if I click it, any pending changes in the property grid do not get written down to the workflow before I run validation and eventually the save.  What gets validated and saved is the pre-edit value of the property, which is clearly problematic (maybe the current value is invalid).

    What really needs to happen on a save is that a pending property edit get commited to the workflow, so that validation and saving happens against the correct property value.  I need to be able to do this in code in order to make sure I'm validating and saving the right thing when I click the toolbar button.

    Any help is appreciated,

    ~Howard

    Tuesday, March 23, 2010 8:48 PM

Answers

  • Think I found a solution.  The following code snipit does the trick.

                ((RoutedCommand) DesignerView.CycleThroughDesignerCommand).Execute(null,
                                                                                   _designer.Context.Services.GetService
                                                                                       <DesignerView>());
                Application.DoEvents();
    

    The "Application.DoEvents()" call is key, otherwise it seems like the CycleThroughDesignerCommand is not actually executed until all pending operations have completed.  Seems like it might make sense to wire this functionality into WorkflowDesigner.Flush, so that anytime it's called, any pending changes in the workflow designer or proeprty grid are applied to the workflow being edited.

    Anyhow, looks like it's solved.

    ~Howard

    • Marked as answer by HKuiz Tuesday, March 23, 2010 9:55 PM
    Tuesday, March 23, 2010 9:55 PM

All replies

  • Hi Howard,

    How are you creating your property grid?  I have a rehosted application that makes use of the property grid, and it commits to xaml as values rae getting set (ie: if you set a boolean, it happens when you click the checkbox.  An expression editor commits on loss of focus)

    The relevent code snippet I use to create the property grid is shown below:

    // initializing my designer:

    this.designer = new WorkflowDesigner();

    // somewhere late in the code:

    private void addPropertyGrid()

    {

    Grid.SetColumn(this.designer.PropertyInspectorView, 2);

    Grid1.Children.Add(this.designer.PropertyInspectorView);

    }

     

    If this isn't quite what you are looking for, posting a code snippet of your own might help us figure out what's going wrong.

    Thanks,

    Eric

    Tuesday, March 23, 2010 9:02 PM
  • Think I found a solution.  The following code snipit does the trick.

                ((RoutedCommand) DesignerView.CycleThroughDesignerCommand).Execute(null,
                                                                                   _designer.Context.Services.GetService
                                                                                       <DesignerView>());
                Application.DoEvents();
    

    The "Application.DoEvents()" call is key, otherwise it seems like the CycleThroughDesignerCommand is not actually executed until all pending operations have completed.  Seems like it might make sense to wire this functionality into WorkflowDesigner.Flush, so that anytime it's called, any pending changes in the workflow designer or proeprty grid are applied to the workflow being edited.

    Anyhow, looks like it's solved.

    ~Howard

    • Marked as answer by HKuiz Tuesday, March 23, 2010 9:55 PM
    Tuesday, March 23, 2010 9:55 PM
  • Hi Eric,

    I'm using the property grid that's created by the WorkflowDesigner control (ie. the PropertyInspectorView).  The expression editor commits just fine on loss of focus, however, there are events (such as clicking a toolbar button) that do not cause the property grid to lose focus (and hence for the expression editor to write down it's expression to the model).  In this case, any expressions that haven't explicilty been committed to the workflow model only exist in the property grid and any operations operating on the model (validation/save, etc) do not account for the "pending" changes.

    The code snippit I pasted above forces any pending expression edits to be written to the model, which is what I was after.  I just tend to think that this will be something that most folks rehosting the designer will want to be able to do easily and integrating it somehow into the designer control would probably be helpful.

    There's not much in the way of a code snippit which I can provide since it's really just the behavior of the PropertyGridInspector control.  I suppose if you take the rehosted designer sample project, drop a toolbar in it and do something like look at the designer's "Text" property in response to a button click on the toolbar, you'll see that pending expressions changes won't be in the XAML.  Clearly when validating the model or saving the XAML, the first thing I want to be sure of is that any pending edits in the designer first get pushed into the model.  It would probably be good to have that functionality wired into the WorkflowDesigner, maybe inthe Flush() command or a separate call.

    Hope that helps.

    ~Howard

    Tuesday, March 23, 2010 10:54 PM