Skip to content

Commit

Permalink
0.2.1 Remove button disabled when no item selected
Browse files Browse the repository at this point in the history
  • Loading branch information
ShinyZero0 committed Dec 30, 2022
1 parent 546a0a5 commit e9fe8fb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
5 changes: 1 addition & 4 deletions ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ public void NewItem()
Content = vm;

}
public void RemoveItem()
{
Items.Items.Remove(Items.Items.ToList().Find(x => x.Name == Items.ItemSelected.Name));
}

public void Save()
{
this.DB.Save(Items.Items);
Expand Down
10 changes: 9 additions & 1 deletion ViewModels/ToDoListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.ObjectModel;
using ToDo.Models;
using ReactiveUI;
using System.Reactive;
using System.Linq;

namespace ToDo.ViewModels
{
Expand All @@ -11,6 +13,7 @@ public class ToDoListViewModel : ViewModelBase
public ToDoListViewModel(IEnumerable<ToDoItem> items)
{
Items = new ObservableCollection<ToDoItem>(items);

}
ToDoItem itemSelected;
public ToDoItem ItemSelected
Expand All @@ -22,7 +25,12 @@ public ToDoItem ItemSelected
set
{
this.RaiseAndSetIfChanged(ref itemSelected, value);
}
}

}
public void RemoveItem()
{
Items.Remove(Items.ToList().Find(x => x.Name == ItemSelected.Name));
}
}
}
2 changes: 1 addition & 1 deletion Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public MainWindow()
{
InitializeComponent();
this.Closing += delegate { ((MainWindowViewModel)this.DataContext).Save(); };
}
}
}

}
2 changes: 1 addition & 1 deletion Views/ToDoListView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ListBox>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Grid.Row="1">
<Button HorizontalAlignment="Center" Command="{Binding $parent[Window].DataContext.NewItem}">Добавить</Button>
<Button HorizontalAlignment="Center" Command="{Binding $parent[Window].DataContext.RemoveItem}">Удалить</Button>
<Button HorizontalAlignment="Center" IsEnabled="{Binding ItemSelected, Converter={x:Static ObjectConverters.IsNotNull}}" Command="{Binding RemoveItem}">Удалить</Button>
</StackPanel>

</Grid>
Expand Down

0 comments on commit e9fe8fb

Please sign in to comment.