1

I cant bind button inside listview to the GoToTask property, every other binding, include second button in the grid is work well.

<Grid>
    <ListView ItemsSource="{Binding Projects}" SelectedItem="{Binding SelectedProject, Mode=TwoWay}" Grid.Row="1">
        <ListView.Resources>
            <Style TargetType="{x:Type GridViewColumnHeader}">
                <Setter Property="Visibility" Value="Collapsed"/>
            </Style>
        </ListView.Resources>
        <ListView.View>
            <GridView>
                <GridViewColumn DisplayMemberBinding="{Binding Name}"/>
                <GridViewColumn Header="Go">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="Go" Command="{Binding Path=GoToTasks, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>
    <Button Height="20" Width="50" HorizontalAlignment="Right" Command="{Binding GoToTasks}" Content="Go"/>
</Grid>

Everything is inside UserControl. What is wrong?

DamianM
  • 468
  • 1
  • 6
  • 15

1 Answers1

2

GridViewColumn is not part of VisualTree and therefore you are not allowed to use FindAncestor.
Similar here. Try ElementName, as far as I remember it uses LogicalTree.

Community
  • 1
  • 1
Maximus
  • 3,458
  • 3
  • 16
  • 27