The F# code did not change significantly between this version and the last; however, the ExpenseItHomeViewModel.fs has been cleaned up due to refactoring and the introduction of the ExpenseReportRepository.
Here's the code:
namespace FSharpWpfMvvmTemplate.ViewModel
open System
open System.Windows
open System.Windows.Data
open System.Windows.Input
open System.ComponentModel
open System.Collections.ObjectModel
open FSharpWpfMvvmTemplate.Model
open FSharpWpfMvvmTemplate.Repository
type ExpenseItHomeViewModel(expenseReportRepository : ExpenseReportRepository) =
inherit ViewModelBase()
let mutable selectedExpenseReport =
{Name=""; Department=""; ExpenseLineItems = []}
new () = ExpenseItHomeViewModel(
FSharpIoC.IoC.GetIoC.Resolve<ExpenseReportRepository>())
member x.ExpenseReports =
new ObservableCollection<ExpenseReport>(
expenseReportRepository.GetAllExpenseReports())
member x.ApproveExpenseReportCommand =
new RelayCommand ((fun canExecute -> true), (fun action -> x.ApproveExpenseReport))
member x.SelectedExpenseReport
with get () = selectedExpenseReport
and set value =
selectedExpenseReport <- value
x.OnPropertyChanged "SelectedExpenseReport"
member x.ApproveExpenseReport =
MessageBox.Show(sprintf "Expense report approved for %s" x.SelectedExpenseReport.Name) |> ignore
You can find the template installer here and the full source at http://github.com/dmohl/PolyglotWpfMvvmTemplate.
No comments:
Post a Comment