Estoy trabajando con MVVM y en lugar de reinventar la rueda, pensé que podría encontrar una clase base de modelo de vista de código abierto. No puedo encontrar unoMVVM: ¿hay una clase base de modelo de vista de código abierto?
Respuesta
Microsoft Prism. Acceso completo al código fuente Una curva de aprendizaje algo empinada, pero una vez que lo manejas, funciona muy bien.
La empinada curva de aprendizaje se aplana si tiene un buen conocimiento de OO y patrones de diseño, y si ya trabajó anteriormente con la inyección de dependencia. –
¿Tiene Prism realmente una clase base de ViewModel? He estado utilizando Prism en algunos proyectos, y en realidad nunca me encontré con eso ... – BFree
La misma pregunta: ¿cómo accedo a ViewModel base en Prism? ¿En qué ensamblado/espacio de nombres está? –
Sugeriría que los principios básicos de MVVM son tan simples que sería más fácil reinventar la rueda. Toda la funcionalidad básica que necesita es que la clase implemente INotifyPropertyChanged
(la clase base podría tener la implementación de estilo estándar de OnPropertyChanged(string propertyName)
). Más allá de eso está el RelayCommand
o similar, solo una implementación ICommand
que ejecuta un delegado en Execute
.
Todo en todos, unas pocas líneas de código, y lo mantiene muy limpio. ¿Qué otra funcionalidad estás buscando? Si se trata de BDO subyacente (digamos DataRow
, XmlNode
o POCO), entonces no debería estar realmente en la clase base de VM, sino en una clase derivada.
Espero que ayude.
Mira el blog de Nikhail Kothari para su biblioteca SilverlightFX, es un MVVM de código abierto que puede serle útil.
MVVM Light también es una buena solución, y tiene un muy fácil de encontrar clase base :-)
Realmente, realmente me gustaría saber de eso antes de presentar mi sugerencia ;-) – heads5150
Aquí es un ejemplo de la mía ... no lo puedo realmente te ayuda, porque quiero Quiero que mis ViewModels a Do será diferente de lo que quieres que hagan tus modelos de vista ... pero quizás te sirva de inicio. Y la cosa con la clase base es si usted se pega en su Core ... solo tiene que escribir una vez ...
Imports System.ComponentModel
Imports System.Windows
Imports Microsoft.Practices.Composite.Events
Imports WavelengthIS.Core.Services
Imports WavelengthIS.Core.Bases
Imports Ocean.OceanFramework.CommonDialog
Imports WavelengthIS.WPF.Events
Namespace WavelengthIS.WPF.Bases
Public MustInherit Class ViewModelBase
Inherits WavelengthIS.Core.Bases.Base
Implements IDisposable, INotifyPropertyChanged
#Region " Declarations "
Private _headerinfo As String
Private _backgroundworker As BackgroundWorker
#End Region
#Region " Properties "
Public Property HeaderInfo() As String
Get
Return _headerinfo
End Get
Set(ByVal value As String)
If Not (value Is String.Empty) Or Not (IsNothing(value)) Then
_headerinfo = value
End If
End Set
End Property
Protected ReadOnly Property BackGroundWorker() As BackgroundWorker
Get
If _backgroundworker Is Nothing Then
_backgroundworker = New BackgroundWorker
End If
Return _backgroundworker
End Get
End Property
Private _isdirty As Boolean = False
Protected Property IsDirty As Boolean
Get
Return _isdirty
End Get
Set(ByVal value As Boolean)
If Not Equals(value, _isdirty) Then
_isdirty = value
If _isdirty = True Then
DisableNavigation()
Else
EnableNavigation()
End If
End If
End Set
End Property
''' <summary>
''' not a databinding property. No need for onpropertychanged notifications
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Protected Property IsLoading As Boolean = False
Private _haschanges As Boolean
Public Property HasChanges As Boolean
Get
Return _haschanges
End Get
Set(ByVal value As Boolean)
If Not Equals(value, _haschanges) Then
_haschanges = value
If value = True Then
GetEvent(Of Events.DisableCloseButtonEvent).Publish(True)
End If
OnPropertyChanged("HasChanges")
End If
End Set
End Property
#End Region
#Region " Dialogs "
'This is not in Bases because it would cause circular references.
''' <summary>
''' Gets the IDialogService registered with the ServiceContainer.
''' use ShowMessage or ShowException in child code.
''' </summary>
Private ReadOnly Property Dialog() As Dialog.IDialogService
Get
Return GetService(Of Dialog.IDialogService)()
End Get
End Property
Protected Function ShowMessage(ByVal message As String, ByVal caption As String, ByVal button As Dialog.DialogButton, ByVal image As Dialog.DialogImage) As Ocean.OceanFramework.CommonDialog.CustomDialogResult
GetEvent(Of Events.DialogShowingEvent).Publish(True)
Dim rslt As CustomDialogResult = Dialog.ShowMessage(message, caption, button, image)
GetEvent(Of Events.DialogShowingEvent).Publish(False)
Return rslt
End Function
Protected Sub ShowException(ByVal message As String, Optional ByVal expandedMessage As String = Nothing, Optional ByVal image As Dialog.DialogImage = Core.Services.Dialog.DialogImage.Error)
GetEvent(Of Events.DialogShowingEvent).Publish(True)
Dialog.ShowException(message, expandedMessage, image)
GetEvent(Of Events.DialogShowingEvent).Publish(False)
End Sub
#End Region
#Region " Wait States "
Private ReadOnly Property Wait As WavelengthIS.Core.Services.IWaitingService
Get
Return GetService(Of IWaitingService)()
End Get
End Property
Protected Sub BeginWait()
GetEvent(Of Events.DisplayWaitingControlEvent).Publish(True)
End Sub
Protected Sub EndWait()
GetEvent(Of Events.DisplayWaitingControlEvent).Publish(False)
End Sub
#End Region
#Region " Events "
Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
#End Region
#Region " Constructor "
Public Sub New()
_backgroundworker = New BackgroundWorker
AddHandler _backgroundworker.DoWork, AddressOf BackGroundWorker_DoWork
AddHandler _backgroundworker.RunWorkerCompleted, AddressOf BackGroundWorker_RunWorkerCompleted
End Sub
#End Region
#Region " IDisposable Support "
Private disposedValue As Boolean = False ' To detect redundant calls
' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
' TODO: free other state (managed objects).
End If
' TODO: free your own state (unmanaged objects).
' TODO: set large fields to null.
End If
Me.disposedValue = True
End Sub
' This code added by Visual Basic to correctly implement the disposable pattern.
Public Sub Dispose() Implements IDisposable.Dispose
' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above.
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
#End Region
#Region " Debugging Helpers "
<Conditional("DEBUG")> _
Public Sub VerifyPropertyName(ByVal propertyName As String)
'If you raise PropertyChanged and do not specify a property name,
'all properties on the object are considered to be changed by the binding system.
If String.IsNullOrEmpty(propertyName) Then
Return
End If
' Verify that the property name matches a real,
' public, instance property on this object.
'If TypeDescriptor.GetProperties(Me)(propertyName) Is Nothing Then
' Dim msg As String = "Invalid property name: " & propertyName
' Throw New Exception(msg)
'End If
End Sub
Private _ThrowOnInvalidPropertyName As Boolean
Protected Property ThrowOnInvalidPropertyName() As Boolean
Get
Return _ThrowOnInvalidPropertyName
End Get
Private Set(ByVal value As Boolean)
_ThrowOnInvalidPropertyName = value
End Set
End Property
#End Region
#Region " INotifyProperty Changed Method "
Protected Overridable Sub OnPropertyChanged(ByVal strPropertyName As String)
Me.VerifyPropertyName(strPropertyName)
If Me.PropertyChangedEvent IsNot Nothing Then
RaiseEvent PropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs(strPropertyName))
End If
End Sub
Private Function QualifyString(ByVal str As String) As Boolean
Return True
End Function
Protected Overridable Sub OnPropertyChanged(ByVal strPropertyName As String, ByVal IsPrimaryProperty As Boolean)
Me.OnPropertyChanged(strPropertyName)
End Sub
#End Region
#Region " Navigation Events "
Protected Sub EnableNavigation()
'Keep from firing multiple onPropertyChanged events
If HasChanges = True Then
HasChanges = False
End If
GetEvent(Of DisableNavigationEvent).Publish(False)
End Sub
Protected Sub DisableNavigation()
'Keep from firing multiple onPropertyChanged events
If HasChanges = False Then
HasChanges = True
End If
GetEvent(Of DisableNavigationEvent).Publish(True)
End Sub
#End Region
End Class
End Namespace
Esta pregunta está etiquetada con C#. – Mizipzor
El WPF Application Framework (WAF) es de código abierto y contiene una clase base ViewModel (por implementando el patrón Model-View-ViewModel).
SoapBox Core es un marco MVVM (y MEF) de fuente abierta (LGPL) para la construcción de aplicaciones extensibles de MVVM. La jerarquía de clases incluye una clase base ViewModel (y una interfaz para el caso).
- 1. MVVM vista de base clase de modelo
- 2. Modelo con base de datos en MVVM
- 3. WPF MVVM modelo de vista DesignMode constructor
- 4. MVVM Modelo de acceso desde la vista
- 5. MVVM duplicar, Características del modelo en modelo de vista
- 6. MVVM - Diferencia entre el modelo y el modelo de vista
- 7. Silverlight MVVM modelo de enlace y vista modelo
- 8. acceso MVVM vista padre modelo desde dentro de la colección
- 9. Cambiar la clase base de una vista de afeitar en el código de vista
- 10. Windows Forms (WinForms) Modelo Ver modelo de modelo de vista (MVVM) a DataBind o no
- 11. ¿Hay una extensión de vista previa de Windows Explorer SVG de código abierto?
- 12. ¿Hay una implementación de código abierto de Java de R2RML?
- 13. ¿hay un servidor asp.net de código abierto?
- 14. ¿Hay algún virus de código abierto?
- 15. ¿Hay algún motor AI de código abierto?
- 16. ¿Hay buenos geoparsers de código abierto disponibles?
- 17. ¿Hay soluciones de código abierto CAPTCHA disponibles?
- 18. Herencia de MVVM con modelos de vista
- 19. Validación: modelo o modelo de vista
- 20. Cómo manejar el subproceso de C# WPF en el modelo de vista de MVVM
- 21. ¿Cómo mantengo la coherencia entre el modelo y el modelo de vista en el patrón MVVM?
- 22. ¿Hay una impresora PDF de código abierto escrita en C++?
- 23. WPF MVVM manera correcta para disparar eventos en vista del modelo de vista
- 24. ASP.NET MVC base genérica vista de clase
- 25. ¿Hay utilidades o jarras de reflexión Java de código abierto?
- 26. Base de datos de gráficos de código abierto
- 27. Plugin de base de datos de código abierto para Eclipse?
- 28. ¿Hay un repositorio de código abierto para código SQL?
- 29. WPF (MVVM): ¿Cerrar una vista desde Viewmodel?
- 30. dónde descargar para la base de código abierto de apple?
¿Qué buscas en esta clase base? –