locked
DataGrid binding in ActivityDesigner RRS feed

  • Question

  • I'm designing a custom activity in which I need a DataGrid (Columns ID, Name, Status), where the user enters information (ID, Name) at design time and at runtime changes the status. For this I havea collection of InArguments in CodeActivity, which I need to bind to the grid from the ActivityDesigner. 

    public sealed class CodeActivity3 : CodeActivity, INotifyPropertyChanged { public CodeActivity3() { People = new ObservableCollection<InArgument<Task>>(); } ObservableCollection<InArgument<Task>> _people; public ObservableCollection<InArgument<Task>> People { get { return _people; } set { if (value == null) return; _people = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("People")); } } } }

    public class Task
        {
           public Task()       {      }

            public string Name { get; set; }
            public string  Status { get; set; }
            public string ID{ get; set; }
        }

    How do I bind the DataGrid (XAML) to my collection of taking into consideration that the first time the collection will be empty and I need to show the empty row in grid for adding data.

    I'm new to WPF and WF so please be patience. Any help will be appreciated.


    PaulM

    Friday, August 17, 2012 12:10 PM

All replies

  • Hi,

    This thread probably can helps:

    WF4 Rehosting Datagrid with WorkflowItemPresenter

    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/73a1cf9e-5b64-48d6-804e-08a05cbe6a60

    Monday, August 20, 2012 3:49 AM
  • From my understanding this is not possible. If some one know that this is possible please let me know :) 

    You should consider changing ObservableCollection<InArgument<Task>> to ObservableCollection<Task>, then you can achieve DataGrid binding for your complex type collection. During design time, from Argument<T> typed-property you can only get the value if the T is string or Literal.

    Hope this link helps: http://blogs.msdn.com/b/tilovell/archive/2011/04/06/wf4-showing-an-inargument-lt-bool-gt-as-a-checkbox-in-the-workflow-designer-property-grid.aspx

    Monday, August 20, 2012 8:47 PM
  • Should be possible, problem is that I don't know how. A Converter can be used to return Task instead of InArgument<Task>. Perhaps InArgument<ObservableCollection<Task>> coud be better. I haven't managed yet to find a solution

    PaulM

    Wednesday, August 22, 2012 10:42 AM
  • Hi Paul,
    I just want to chip in with some random advice based on reading the code and mostly ignoring the question.

    I would like to encourage you to try avoiding using ObservableCollection on your activity class. Here are two points to consider:

    1) At design time you can potentially use the ModelItemCollection, or put an ObservableCollection on your designer class instead. In any case you should actually make edits to the collection on the activity via ModelItemCollection, because WF designer needs that in order for Undo, Redo, etc to work properly.

    2) At runtime you are not allowed to change the set of arguments anyway, so there's no point observing changes.

    You also should probably not need to implement INotifyPropertyChanged on your activity class, as you can bind to the ModelItem instead.

    Tim

    • Marked as answer by LeoTang Sunday, August 26, 2012 1:08 PM
    • Unmarked as answer by MPaul Wednesday, August 29, 2012 2:05 PM
    Thursday, August 23, 2012 8:16 PM
  • Hi Paul,
    I just want to chip in with some random advice based on reading the code and mostly ignoring the question.

    I would like to encourage you to try avoiding using ObservableCollection on your activity class. Here are two points to consider:

    1) At design time you can potentially use the ModelItemCollection, or put an ObservableCollection on your designer class instead. In any case you should actually make edits to the collection on the activity via ModelItemCollection, because WF designer needs that in order for Undo, Redo, etc to work properly.

    2) At runtime you are not allowed to change the set of arguments anyway, so there's no point observing changes.

    You also should probably not need to implement INotifyPropertyChanged on your activity class, as you can bind to the ModelItem instead.

    Tim

    Hello Tim,

    I was away from for the last few days and couldn't answer. Thanks for the suggestions. They are welcomed, but unfortunately don't answer my question. I've tried various ways, with/without ObservableCollection, but no result yet


    PaulM

    Wednesday, August 29, 2012 2:05 PM