DataContext not released with Command Binding in DataTemplate RRS feed

  • Question

  • I have a button in an item template in a GridView that uses Command binding to call a method on the ViewModel when the button is clicked. The ViewModel is never released. The Template:

    <DataTemplate x:Key="ItemTemplate">
            <Button HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,0,0,0"
                                                 Command="{Binding ElementName=LayoutRoot, Path=DataContext.NavigateToOtherPageCommand}"/>

    If I remove the Command property OR if I comment out the public property (that is never set BTW) in the ViewModel:

    // public ICommand NavigateToOtherPageCommand { get; private set; }

    there is no leak. Any help would be appreciated!

    Tuesday, January 22, 2013 11:39 AM

All replies

  • I seem to remember there being a memory leak in WPF when not implementing INPC on properties you bound to, maybe this issue persists on Windows XAML as well?
    Wednesday, January 23, 2013 7:30 AM