things
This commit is contained in:
@@ -1,13 +1,26 @@
|
||||
using WD7UVN_HFT_2023241.Models;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System.Windows.Input;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
|
||||
{
|
||||
public class GetAllServicesViewModel
|
||||
public class GetAllServicesViewModel : ObservableRecipient
|
||||
{
|
||||
public RestCollection<Service> Services { get; set; }
|
||||
|
||||
private Service selectedService;
|
||||
|
||||
public Service SelectedService
|
||||
{
|
||||
get { return selectedService; }
|
||||
set { SetProperty(ref selectedService, value); (UpdateServiceCommand as RelayCommand).NotifyCanExecuteChanged(); }
|
||||
}
|
||||
|
||||
public ICommand UpdateServiceCommand { get; set; }
|
||||
|
||||
public static bool IsInDesignMode
|
||||
{
|
||||
get
|
||||
@@ -22,6 +35,15 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
|
||||
if (!IsInDesignMode)
|
||||
{
|
||||
Services = new RestCollection<Service>("http://localhost:5000/", "api/Service", "hub");
|
||||
|
||||
UpdateServiceCommand = new RelayCommand(() =>
|
||||
{
|
||||
Services.Update(SelectedService);
|
||||
},
|
||||
() =>
|
||||
{
|
||||
return SelectedService != null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<RowDefinition Height="9*" />
|
||||
<RowDefinition Height="1*" />
|
||||
</Grid.RowDefinitions>
|
||||
<ListBox ItemsSource="{Binding Services}" Grid.Row="0">
|
||||
<ListBox ItemsSource="{Binding Services}" Grid.Row="0" SelectedItem="{Binding SelectedService}">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
@@ -78,7 +78,7 @@
|
||||
|
||||
<UniformGrid Rows="2" Grid.Row="1">
|
||||
<Button Content="Create new" Click="CreateNewService" />
|
||||
<Button Content="Edit selected" />
|
||||
<Button Content="Edit selected" Command="{Binding UpdateServiceCommand}"/>
|
||||
</UniformGrid>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
Reference in New Issue
Block a user