Problem z bindowaniem do ViewModel

0

View

<UserControl.DataContext>
        <ViewModels:ShelfViewModel/>
    </UserControl.DataContext>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="0.2*"/>
            <RowDefinition/>
        </Grid.RowDefinitions>

        <StackPanel Orientation="Horizontal">
            <StackPanel.Resources>
                <ResourceDictionary Source="Resources/Images.xaml"/>
            </StackPanel.Resources>
            <Button Content="{StaticResource Img_AddSquareSmall}" Command="{Binding AddBookCommand}"/>
        </StackPanel>
        <ListBox Grid.Row="1" ItemsSource="{Binding Books}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <Image Source="{Binding Path=CoverImage}"/>
                        <TextBlock Text="{Binding Path=Title}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</UserControl>

ViewModel:

public class ShelfViewModel : ViewModelBase
    {
        readonly IShelfService ShelfService;
        readonly ObservableCollection<EpubBook> Books;

        public ICommand AddBookCommand;
        public ICommand RemoveBookCommand;

        public ShelfViewModel()
        {
            ShelfService = ServiceLocator.Instance.GetService<IShelfService>();
            Books = ShelfService.Books;

            InitializeCommands();
        }

        void InitializeCommands()
        {
            AddBookCommand = new RelayCommand(AddBook);
        }

        void AddBook(object p)
        {
            ShelfService.LoadBook();
        }
    }

Konstruktor w VM się wykonuje, ale AddBook(object) nigdy nie jest wykonywane.

1

Ale ICommand AddBookCommand powinno być chyba propertisem. Czyli mieć get oraz set. Generalnie wszystko co się binduje powinno mieć get oraz set. Tak mi się wydaje.

1 użytkowników online, w tym zalogowanych: 0, gości: 1