Code WPF RentABike


internal class Bike
{
  public string model;
  public int pricePerHour;
  public DateTime take;

  public Bike(string model, int pricePerHour)
  {
    this.model = model;
    this.pricePerHour = pricePerHour;
  }

  public override string ToString()
  {
    return model + " " + pricePerHour + " €";
  }
}

Додати
lb1.Items.Add(new Bike(tb1.Text, int.Parse(tb2.Text)));
 
Взяти
if (lb1.SelectedItem != null)
{
  ((Bike)lb1.SelectedItem).take = DateTime.Now;
  lb2.Items.Add(lb1.SelectedItem);
  lb1.Items.Remove(lb1.SelectedItem);
}

Повернути
if (lb2.SelectedItem != null)
{
  int pricePerHour = ((Bike)lb2.SelectedItem).pricePerHour;
  DateTime d1 = ((Bike)lb2.SelectedItem).take;
  DateTime d2 = DateTime.Now;
  double time = Math.Round((d2 - d1).TotalHours, 2);
  MessageBox.Show(time + " * " + pricePerHour + " = " + time * pricePerHour + " €");
  lb1.Items.Add(lb2.SelectedItem);
  lb2.Items.Remove(lb2.SelectedItem);
}
  
<Window x:Class="RentABike.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:RentABike"
        mc:Ignorable="d"
        Title="Rent A Bike" Height="450" Width="800" Background="#FFEDA59E">
  <Grid Margin="10" Background="#FFC0DAAE">
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <ListBox x:Name="lb1" Grid.Column="0" Margin="10" FontSize="30"/>
    <ListBox x:Name="lb2" Grid.Column="2" Margin="10" FontSize="30"/>
    <Grid Grid.Column="1" Margin="10,10,10, 20">
      <Grid.RowDefinitions>
        <RowDefinition Height="1.5*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
      </Grid.RowDefinitions>
      <Image Source="/cooltext431733584055871.png" />
      <Button Grid.Row="1" Content="Take" FontSize="30" Click="Button_Click_1"/>
      <Button Grid.Row="2" Content="Return" FontSize="30" Click="Button_Click_2"/>
      <TextBox x:Name="tb1" Grid.Row="3" FontSize="30"/>
      <TextBox x:Name="tb2" Grid.Row="4" FontSize="30"/>
      <Button Grid.Row="5" Content="Add" FontSize="30" Click="Button_Click"/>
      <Button Grid.Row="6" Content="Remove" FontSize="30"/>
    </Grid>
  </Grid>
</Window>