Reputation: 5375
In my WPF Caliburn.Micro application, I have a TabControl. I want to be able to close tabs as needed. I found a way to do it here:
But when I try to apply it, I get an error:
No target found for method CloseItem.
Here is my code:
<TabControl x:Name="Items" >
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding DisplayName}" />
<Button Content="X"
cal:Message.Attach="CloseItem($dataContext)" />
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
Could you please help?
Thanks.
Upvotes: 3
Views: 814
Reputation: 12656
Another way of doing it would be:
<Button Content="X" cal:Message.Attach="DeactivateItem($dataContext, 'true')" />
that way you don't have to create an extra method.
Upvotes: 7
Reputation: 1825
Not entirely certain what's causing your exact issue (I suspect a very old tutorial coupled with a vastly different assembly is the issue) but I know how you can get it to work. Create any old public method like this and call it. It's going to override what you've got in there so you could name it CloseItem. Then call this extension method and pass in the IConductor instance and the IScreen instance.
public void CloseItem(object dataContext)
{
ScreenExtensions.CloseItem(this, dataContext);
}
Upvotes: 2