Одна кнопка на два листа
Есть лист(Желаю прочитать) куда пользователь добавляет книги.И так же есть 2 кнопки.Первая которая переносит книгу в второй лист (Прочитонные книги).И Вторая которая удаляет элемент.И с помощью кнопки удаления пользователь может удалять книгу как из 1 так из 2 листа.Как сделать эту чертову кнопку удаления.
Вью:
<Window x:Class="BOOKLIST.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BOOKLIST"
mc:Ignorable="d"
Title="MainWindow" Height="489.519" Width="826.987">
<Window.DataContext>
<local:BookVM/>
</Window.DataContext>
<DockPanel>
<StackPanel DockPanel.Dock="Top">
<TextBox x:Name="BookName" Width="200" Height="30" VerticalContentAlignment="Center" Margin="5"/>
<Button Command="{Binding AddCommand}" CommandParameter="{Binding ElementName=BookName , Path=Text}" Height="30" Width="250" Content="Add To Whishlist" FontSize="20"/>
</StackPanel>
<!-- Whishlist Zone -->
<StackPanel DockPanel.Dock="Left" HorizontalAlignment="Left" Margin="5">
<Label Width="200" Height="50" Content="Whishlist" HorizontalContentAlignment="Center" VerticalContentAlignment="Top" FontSize="30" Margin="10"/>
<ListBox x:Name="Whishlist" ItemsSource="{Binding WhishlistView}" Height="300" Width="300" />
</StackPanel>
<!-- Readed Zone -->
<StackPanel DockPanel.Dock="Right" HorizontalAlignment="Right" Margin="5">
<Label Width="200" Height="50" Content="Readed" HorizontalContentAlignment="Center" VerticalContentAlignment="Top" FontSize="30" Margin="10"/>
<ListBox x:Name="Readed" Height="300" Width="300"/>
</StackPanel>
<!-- Buttons (midle) -->
<StackPanel VerticalAlignment="Center">
<Button Height="30" Margin="5" Content="Move to Readed" FontSize="20"/>
<Button Command="{Binding RemoveCommand}" Height="25" Margin="10" Content="Remove" FontSize="17"/>
</StackPanel>
</DockPanel>
</Window>
Это вью модель :
using Prism.Commands;
using System.Collections.ObjectModel;
namespace BOOKLIST
{
class BookVM
{
BookModel bookM;
public DelegateCommand<string> AddCommand { get; private set; }
public DelegateCommand RemoveCommand { get; private set; }
public DelegateCommand MoveCommand { get; private set; }
public ReadOnlyObservableCollection<string> WhishlistView => bookM.Whishlist;
public ReadOnlyObservableCollection<string> ReadedView => bookM.Readed;
public void Add(string value)
{
bookM.AddToWhishlist(value);
}
public void Move(int index)
{
}
public void Remove(int index)
{
}
public BookVM()
{
bookM = new BookModel();
AddCommand = new DelegateCommand<string>(Add);
}
}
}
модель
using System.Collections.ObjectModel;
namespace BOOKLIST
{
class BookModel
{
private readonly ObservableCollection<string> _whishlist = new ObservableCollection<string>();
public readonly ReadOnlyObservableCollection<string> Whishlist;
private readonly ObservableCollection<string> _readed = new ObservableCollection<string>();
public readonly ReadOnlyObservableCollection<string> Readed;
public BookModel()
{
Whishlist = new ReadOnlyObservableCollection<string>(_whishlist);
Readed = new ReadOnlyObservableCollection<string>(_readed);
}
public void AddToWhishlist(string value)
{
_whishlist.Add(value);
}
public void MoveToReaded(int index)
{
}
public void Remove(int index , string listName)
{
if (listName == "Whishlist")
{
_whishlist.RemoveAt(index);
}
else if (listName == "Readed")
{
_readed.RemoveAt(index);
}
}
public void MoveToReaded()
{
// For later
}
}
}