Button command does not run in listview group header

I have a listview with an extensible title, this works correctly, however, when I add a button, it does not start the linked command.

<ControlTemplate>
    <Expander IsExpanded="True">
        <Expander.Header>
            <StackPanel Orientation="Horizontal">
                   <TextBlock Text="{Binding Name}" Name="txtX" FontWeight="Bold"   Foreground="Gray" FontSize="22" VerticalAlignment="Bottom" />
                   <Button Content="Add Task List" Width="150" HorizontalAlignment="Right" Command="{Binding XCommand}"/>
            </StackPanel>
        </Expander.Header>
    <ItemsPresenter />
    </Expander>
</ControlTemplate>

All other buttons on the page correctly control the commands of my view mode, so I will be afraid to guess that this is due to xaml or how the buttons are created dynamically with each grouping.

* CHANGE

Just add the appropriate view model code for the context. If I add an identical button outside the list, it launches the command. Link to the image of all xaml.

#Region "Properties"
    Public Property XCommand As ICommand
#End Region

#Region "  Constructors"
    Public Sub New(ByVal regionManager As IRegionManager, _
                   ByVal container As IUnityContainer)
        XCommand = New RelayCommand(AddressOf DoSomething) 
        _regionManager = regionManager
        _container = container    
    End Sub
#End Region

#Region "Command methods"
    Private Sub DoSomething()
        MessageBox.show("Test")
    End Sub
#End Region

Any help on how to make this work correctly?

Thankyou!

+3
source share
1 answer

GroupItem, GroupItem. ( ListView). , RelativeSource:

<Button Command="{Binding DataContext.XCommand, RelativeSource={RelativeSource AncestorType=ListView}}"
        Content="Add Task List" Width="150" HorizontalAlignment="Right" />
+2

All Articles