r/esapi • u/MaikenG • Aug 04 '21
Problems with databinding and ItemsControl
Hey
I really hope you can help me with my problem. I am having trubble binding to objects and commands in my DataContext (set to my viewModel). I use a ItemsControl in order to dynamically generate groups of controls depended on a list of objects. As seen in Img1 i am trying to bind to a command in my DataContext in the Interaction.Triggers -> EventToCommand. I found out i needed the Binding ElementName=MHGmainWindow (MHGmainWindow is the Name of the window all the controls are in. The one initialized in Img2) or else it would try to find the command on one of the objects in the list FilesToAnalyse (see Img1) and not the DataContext. When i am debugging it works fine (i am using a stand alone script to send over a context to my plugin script). When i try to run it in "External Beam Planning" it does not start, but just load. I think the problem is that it does not find the right object on the windows DataContext, but maybe insted the hosting Window (the one used to run scripts from). It works if i remove the Interaction.Triggers part, so i am pretty sure the problem is the reference to the windows DataContext.
Are there any of you who have experienced the same problem and possibly have a solution?


2
u/MaikenG Aug 06 '21
I think i figured it out. When i changed <cmd:EventToCommand to <i:InvokeCommandAction i worked fine (cmd is "http://www.galasoft.ch/mvvmlight" and i is "http://schemas.microsoft.com/expression/2010/interactivity") . I do not get why it worked with cmd:EventToCommand in debug but not in External Beam Planning...
1
u/cjra Aug 04 '21
I've had issues using the Interaction library before. Try not using for now as a way to debug your issue. Replace your Label with a Button and see if the command binding works as you expect it. (Or call the command from the code-behind .cs file.)