Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.

Pergunta DataGrid binding in ActivityDesigner

  • sexta-feira, 17 de agosto de 2012 12:10
     
      Contém Código

    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

Todas as Respostas

  • segunda-feira, 20 de agosto de 2012 03:49
     
     

    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

  • segunda-feira, 20 de agosto de 2012 20:47
     
     

    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

  • quarta-feira, 22 de agosto de 2012 10:42
     
     
    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

  • quinta-feira, 23 de agosto de 2012 20:16
    Moderador
     
     

    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

    • Marcado como Resposta LeoTangModerator domingo, 26 de agosto de 2012 13:08
    • Não Marcado como Resposta MPaul quarta-feira, 29 de agosto de 2012 14:05
    •  
  • quarta-feira, 29 de agosto de 2012 14:05
     
     

    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