Command is null inside ItemControl?

Topics: Prism v1
Feb 4, 2009 at 1:01 AM
Hi,
I have a ListBox which I drag items from another ListBox to it. Because ListBox doesn't have a command attribute I use a hiddin button and in the drop event handler I do:

private void HandleDrop(object sender, DragEventArgs e)
{
...
hiddenButton.Command..Execute(sourceListBox.SelectedItem);
}

This is working fine in various screens. However, now I want to use the same idea inside an ItemControl but the Command of the hiddenButton is coming back as Null...

Here's the XAML:

<

 

ItemsControl ItemsSource="{Binding CurrentFileType.FileTypeIssues}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel >
<Expander HorizontalContentAlignment="Center" Header="{Binding Path=Issues.Name}" >
<ListBox AllowDrop="True" DisplayMemberPath="Name" Drop="DropHandler" ItemsSource="{Binding Resolutions}" />
</Expander>
<Button Command="{Binding ResolutionAdded}" x:Name="hiddenButton" Visibility="Collapsed"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

 Is there a reason the Command is Null inside an ItemControl? Is there a workaround?

 Thank you,

Ken

Feb 4, 2009 at 1:47 PM
Edited Feb 4, 2009 at 1:48 PM

Hi Ken,

 

A possible reason for the command being null could bea binding error. The ResolutionAdded command property needs to be in each instance of the CurrentFileType.FileTypeIssues collection for it to be bound correctly, if using that Binding syntax. You could check if that is the cause of the null command.

If the issue is related to the fact that these instances are not exposing the command, you should consider using a different source (RelativeSource or ElementName) for the command binding to work correctly.

 

It might be useful to look at the debug output which should show a binding error that might help track down the cause of your issue.

 

Please let me know if this helps.

 

Damian Schenkelman

http://blogs.southworks.net/dschenkelman
Feb 4, 2009 at 6:00 PM
Hi Damian,
Thank you. I understand now that once I bound the item control to the CurrentFile.FileTypeIssues collection it's looking for resolusionAdded as a property of FileTypeIssue (and indeed I could see it it the debug output). CurrentFile.FileTypeIssues does not contain a resolusionAdded command. This command is a delegate command which is defined in the presetationModel class of this view. My question now is what other sysntax can I use in the command attribute in order to make it work?
Thank you,
Ken