Bind Collection to ListView, suppress duplicates of object but manipulate ListViewItem

Viewed 86

My problem, developing a shopping system on a Raspberry Pi 3 Bodel B, is as following:

First of all some context:

  1. Raspberry Pi with Barcode Scanner is used as self-service shop

    • Employees scans a drink and the price on the screen is added up the price of the drink
    • Now a extension should be provided: A list of all currently scanned products should be shown.
  2. Until now I only achieved, that every scanned product appears as one ListViewItem in the ListView

This is my Model

    public partial class Product : object, System.ComponentModel.INotifyPropertyChanged {
    private string DescriptionField;
    private System.DateTime ExpirationDateField;
    private int IDField;
    private string NameField;
    private decimal PriceField;

    [System.Runtime.Serialization.DataMemberAttribute()]
    public string Description {
        get {
            return this.DescriptionField;
        }
        set {
            if ((object.ReferenceEquals(this.DescriptionField, value) != true)) {
                this.DescriptionField = value;
                this.RaisePropertyChanged("Description");
            }
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute()]
    public System.DateTime ExpirationDate {
        get {
            return this.ExpirationDateField;
        }
        set {
            if ((this.ExpirationDateField.Equals(value) != true)) {
                this.ExpirationDateField = value;
                this.RaisePropertyChanged("ExpirationDate");
            }
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute()]
    public int ID {
        get {
            return this.IDField;
        }
        set {
            if ((this.IDField.Equals(value) != true)) {
                this.IDField = value;
                this.RaisePropertyChanged("ID");
            }
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute()]
    public string Name {
        get {
            return this.NameField;
        }
        set {
            if ((object.ReferenceEquals(this.NameField, value) != true)) {
                this.NameField = value;
                this.RaisePropertyChanged("Name");
            }
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute()]
    public decimal Price {
        get {
            return this.PriceField;
        }
        set {
            if ((this.PriceField.Equals(value) != true)) {
                this.PriceField = value;
                this.RaisePropertyChanged("Price");
            }
        }
    }

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName) {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}

This model describes a product which can be bought in our shop.

My XAML Snippet

<ListView Name="ProductSumUp" 
          AllowDrop="False"  
          SelectionMode="None" 
          CanDrag="False" 
          CanReorderItems="False" 
          CanDragItems="False" 
          Grid.Column="2" 
          HorizontalAlignment="Left" 
          Height="290" 
          Margin="10,10,0,0" 
          Grid.Row="1" 
          VerticalAlignment="Top" 
          Width="180" 
          RenderTransformOrigin="1.682,0.59" 
          Foreground="White" 
          FontFamily="Assets/Fonts/Baskerville.ttf#Baskerville">
        <ListView.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <TextBlock FontFamily="Assets/Fonts/Baskerville.ttf#Baskerville" 
                               Foreground="White">
                        <Run Text="{Binding Name}"/>
                        <Run x:Name="{Binding Price}"/>
                        </TextBlock>
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

Now my question is:

Is it possible, if a product was scanned twice, not to add a new ListViewItem, instead, the existing ListViewItem should be manipulated by adding the same Price on the existing Item.

I tried many possibilities and also asked some developers at my work but nobody could figure out.

If you need more information just ask.

Thanks in advance and excuse me for my horrible English grammar :)

1 Answers
Related