Click here to Skip to main content
15,895,142 members
Articles / Programming Languages / Visual Basic 10

Generic Multi-Select MVVM ListBox Drag and Drop Helper with Custom Feedback for Silverlight 4.0

Rate me:
Please Sign up or sign in to vote.
4.91/5 (3 votes)
11 Apr 2011CPOL9 min read 53.4K   982   13  
This article focuses on developing an MVVM compatible ListBox-to-ListBox drag/drop helper for Silverlight.
'/* Copyright (c) 2011, Graeme Grant (gragra33@hotmail.com)
' * All rights reserved.
' *
' * Redistribution and use in source and binary forms, with or without
' * modification, are permitted provided that the following conditions are met:
' *
' *   * Redistributions of source code must retain the above copyright
' *     notice, this list of conditions and the following disclaimer.
' * 
' *   * Redistributions in binary form must reproduce the above copyright
' *     notice, this list of conditions and the following disclaimer in the
' *     documentation and/or other materials provided with the distribution.
' * 
' * THIS SOFTWARE IS PROVIDED BY GRAEME GRANT ``AS IS'' AND ANY
' * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
' * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
' * DISCLAIMED. IN NO EVENT SHALL GRAEME GRANT BE LIABLE FOR ANY
' * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
' * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
' * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
' * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
' * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
' * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
' */

Imports Helpers
Imports System.Collections.ObjectModel

Public Class ProductModel : Inherits ModelBase

#Region "Constructor"

    Sub New()
        '
    End Sub

#End Region

#Region "Properties"

    Public Const product_idPropertyName As String = "product_id"

    Private _product_id As Integer
    Public Property product_id As Integer
        Get
            Return _product_id
        End Get
        Set(ByVal value As Integer)
            If _product_id = value Then
                Return
            End If
            _product_id = value
            RaisePropertyChanged(product_idPropertyName)
        End Set
    End Property

    Public Const TitlePropertyName As String = "title"

    Private _title As String
    Public Property title As String
        Get
            Return _title
        End Get
        Set(ByVal value As String)
            If _title = value Then
                Return
            End If
            _title = value
            RaisePropertyChanged(TitlePropertyName)
        End Set
    End Property

    Public Const pricePropertyName As String = "price"

    Private _price As Decimal
    Public Property price As Decimal
        Get
            Return _price
        End Get
        Set(ByVal value As Decimal)
            If _price = value Then
                Return
            End If
            _price = value
            RaisePropertyChanged(pricePropertyName)
        End Set
    End Property

    Public Const quantityPropertyName As String = "quantity"

    Private _quantity As Integer
    Public Property quantity As Integer
        Get
            Return _quantity
        End Get
        Set(ByVal value As Integer)
            If _quantity = value Then
                Return
            End If
            _quantity = value
            RaisePropertyChanged(quantityPropertyName)
        End Set
    End Property

    Public Const viewsPropertyName As String = "views"

    Private _views As Integer
    Public Property views As Integer
        Get
            Return _views
        End Get
        Set(ByVal value As Integer)
            If _views = value Then
                Return
            End If
            _views = value
            RaisePropertyChanged(viewsPropertyName)
        End Set
    End Property

    Public Const num_likesPropertyName As String = "num_likes"

    Private _num_likes As Integer
    Public Property num_likes As Integer
        Get
            Return _num_likes
        End Get
        Set(ByVal value As Integer)
            If _num_likes = value Then
                Return
            End If
            _num_likes = value
            RaisePropertyChanged(num_likesPropertyName)
        End Set
    End Property

    Public Const tagsPropertyName As String = "tags"

    Private _tags As ObservableCollection(Of TagModel)
    Public Property tags As ObservableCollection(Of TagModel)
        Get
            Return _tags
        End Get
        Set(ByVal value As ObservableCollection(Of TagModel))
            If tags Is value Then
                Return
            End If
            _tags = value
            RaisePropertyChanged(tagsPropertyName)
        End Set
    End Property

    Public Const groupPropertyName As String = "group"

    Private _group As GroupModel
    Public Property group As GroupModel
        Get
            Return _group
        End Get
        Set(ByVal value As GroupModel)
            If group Is value Then
                Return
            End If
            _group = value
            RaisePropertyChanged(groupPropertyName)
        End Set
    End Property

#End Region

    Public Overrides Function ToString() As String
        Return String.Format("ID: {0} / Title: {1} / Tags: {2} / group ID: {3}", product_id, title, tags.Count, group.group_id)
    End Function

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions