共用方式為


Designer in View

Recently, a customer asked how can we get the designer in focus if we know the Model Item for that activity. This can specifically be of value as you are working with large workflows and huge scrolling for going from top to the bottom.

This can now be achieved pretty simple:

modelItem.Focus();

Thus, once you know the model item you want to access, call modelItem.Focus and this should bring it in view and set focus on it.

Another interesting thing that happened when I was cooking up this sample :Essentially, I had a custom designer for an activity with a button on it. In the button click event handler, I was getting hold of the activity’s model item and then:

  using (ModelEditingScope editingScope = this.ModelItem.Root.BeginEdit("Activities"))
{
        this.ModelItem.Root.Properties["Activities"].Collection.Add(new Sequence());
        //Do this multiple times to have scrolls introduced in the designer due to the large workflow size

}

Then to set the focus on my activity with button, I did: this.ModelItem.Focus(). However this didn't work. The focus still remained on the last Sequence activity added. The trick was actually to do it this way:

  Dispatcher.Invoke(DispatcherPriority.ApplicationIdle, (System.Action)(() =>
 {
        myItem.Focus();
  }));

The reason being, the added model items themselves set the focus on them through an idle. Hence we need to queue up our idle after them. Hence the Dispatcher.Invoke with the action on ApplicationIdle.

Hope this helps!

Thanks,

Kushal.