Click here to Skip to main content
15,879,535 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: How to check all rows in DataGrid by clicking Check all Button in WPF in C# Pin
Pete O'Hanlon27-Oct-09 0:56
mvePete O'Hanlon27-Oct-09 0:56 
GeneralRe: How to check all rows in DataGrid by clicking Check all Button in WPF in C# Pin
ChandrakanthGaddam27-Oct-09 1:08
ChandrakanthGaddam27-Oct-09 1:08 
GeneralRe: How to check all rows in DataGrid by clicking Check all Button in WPF in C# Pin
Pete O'Hanlon27-Oct-09 1:36
mvePete O'Hanlon27-Oct-09 1:36 
QuestionReference to parent collection Pin
ausadmin26-Oct-09 19:38
ausadmin26-Oct-09 19:38 
AnswerRe: Reference to parent collection Pin
Pete O'Hanlon26-Oct-09 22:44
mvePete O'Hanlon26-Oct-09 22:44 
GeneralRe: Reference to parent collection Pin
ausadmin27-Oct-09 9:54
ausadmin27-Oct-09 9:54 
GeneralRe: Reference to parent collection Pin
Pete O'Hanlon27-Oct-09 10:12
mvePete O'Hanlon27-Oct-09 10:12 
GeneralRe: Reference to parent collection Pin
ausadmin27-Oct-09 19:16
ausadmin27-Oct-09 19:16 
Pete,

Thanks for the suggestion of using a ViewModel. I am a big fan of using ViewModel and have made extensive use of this pattern in our project (where it fits). I found your article "Action based ViewModel and Model validation." and Josh Smith's article "Using a ViewModel to Provide Meaningful Validation Error Messages" on this approach (I assume that is what you meant), and have now modified the project accordingly.

So the original class was ATUser and I defined a new UserViewModel class which wraps ATUser. I have been able to achieve the validation (and it works nicely), however I am still not sure I am following good programming practise (really my original question), because I found it essential to pass a reference to the ObservableCollection (container collection), into each UserViewModel member, so the member could find out if the user name had already been used.

So a snippet of UserViewModel is
Public Class UserViewModel
    Implements INotifyPropertyChanged
    Implements IDataErrorInfo

    Private _user As ATUser
    Private _containerCollection As AUSObservableCollection(Of UserViewModel)

    Public Sub New(ByRef User As ATUser, _
                   ByRef ContainerCollection As AUSObservableCollection(Of UserViewModel))
        _user = User
        _containerCollection = ContainerCollection
        _username = _user.Username
    End Sub

    'lines removed
    Default Public ReadOnly Property Item(ByVal propertyName As String) As String Implements IDataErrorInfo.Item
        Get
            Select Case propertyName
                Case "Username"
                'logic to determine if Username is valid, which involves searching through _containerCollection 
            End Select
        End Get
    End Property
End Class


So I believe I have achieved the goals of using the ViewModel, which include improved control over Data Validation. However I'm not sure I addressed my original concern - which is holding a reference to the containing collection within the member object itself.... Could you comment on whether I have missed the point / whether there is a more acceptable way to solve this / whether the reference to the containing collection is OK? Just to restate, in order for a UserViewModel to validate the Username property, it needs to access the containing collection, in order to see if the name has already been used.

From the Data Validation point of view, I could have achieved the same by implementing IDataErrorInfo on the ATUser class, and simply adding a Property to hold the reference to the containing collection (which would take much less time and be easier to maintain, but would loose the other benefits of ViewModel). I have about 9 similar classes in this project, so I would like to get this right before moving on.

Thanks again for your help, and apologies if I am asking a basic question.

Tim
GeneralRe: Reference to parent collection Pin
ausadmin29-Oct-09 1:33
ausadmin29-Oct-09 1:33 
QuestionUserControl - visualbrush not rendered Pin
DeepakMega26-Oct-09 3:04
DeepakMega26-Oct-09 3:04 
AnswerRe: UserControl - visualbrush not rendered Pin
DeepakMega26-Oct-09 4:16
DeepakMega26-Oct-09 4:16 
Question3D Graphics C# and WPF Browser Application Pin
427748025-Oct-09 9:04
427748025-Oct-09 9:04 
GeneralRe: 3D Graphics C# and WPF Browser Application Book recommendation Pin
Richard MacCutchan25-Oct-09 13:31
mveRichard MacCutchan25-Oct-09 13:31 
AnswerRe: 3D Graphics C# and WPF Browser Application Pin
Death8U29-Oct-09 7:31
Death8U29-Oct-09 7:31 
QuestionMVVM Pattern Pin
NETLearning24-Oct-09 18:21
NETLearning24-Oct-09 18:21 
AnswerRe: MVVM Pattern Pin
Richard MacCutchan24-Oct-09 23:07
mveRichard MacCutchan24-Oct-09 23:07 
AnswerRe: MVVM Pattern Pin
Steve Westbrook26-Oct-09 7:00
Steve Westbrook26-Oct-09 7:00 
QuestionWPF MVVM Pin
NETLearning24-Oct-09 15:02
NETLearning24-Oct-09 15:02 
AnswerRe: WPF MVVM Pin
Richard MacCutchan24-Oct-09 23:08
mveRichard MacCutchan24-Oct-09 23:08 
QuestionMVVM newbie question - showing OpenFileDialog? Pin
Judah Gabriel Himango24-Oct-09 14:33
sponsorJudah Gabriel Himango24-Oct-09 14:33 
AnswerRe: MVVM newbie question - showing OpenFileDialog? Pin
Pete O'Hanlon25-Oct-09 9:36
mvePete O'Hanlon25-Oct-09 9:36 
GeneralRe: MVVM newbie question - showing OpenFileDialog? Pin
Judah Gabriel Himango25-Oct-09 16:01
sponsorJudah Gabriel Himango25-Oct-09 16:01 
GeneralRe: MVVM newbie question - showing OpenFileDialog? Pin
Pete O'Hanlon25-Oct-09 22:05
mvePete O'Hanlon25-Oct-09 22:05 
QuestionWpf Pin
miralireza24-Oct-09 8:44
miralireza24-Oct-09 8:44 
AnswerRe: Wpf Pin
Pete O'Hanlon24-Oct-09 9:13
mvePete O'Hanlon24-Oct-09 9:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.