unit View.Form.MainView;
interface
uses
de.itnets.Events,
de.itnets.References,
MVVM.ViewModel.ViewModelBase,
ViewModel.MainViewModel,
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
View.Form.WorkspaceView, MVVM.View.FMX.Frame.Base, View.Frame.AcitivityView,
FMX.Objects, System.Actions, FMX.ActnList, FMX.Layouts;
type
TMainView =
class( TWorkspaceView )
ActivityCurtain: TRectangle;
ActivityView1: TActivityView;
ToolBar1: TToolBar;
SpeedButton1: TSpeedButton;
ActionList1: TActionList;
SomeActionAction: TAction;
procedure SomeActionActionExecute(Sender: TObject);
procedure SomeActionActionUpdate(Sender: TObject);
private
FMain: WeakRef<TMainViewModel>;
protected
procedure AttachToViewModel( AViewModel: TViewModelBase );
override;
procedure DetachFromViewModel( AViewModel: TViewModelBase );
override;
procedure ViewModelPropertyChanged( Sender: TObject;
const e: TPropertyChangedArgs );
override;
public
end;
var
MainView: TMainView;
implementation
{$R *.fmx}
uses
System.StrUtils;
{ TMainView }
procedure TMainView.AttachToViewModel( AViewModel: TViewModelBase );
begin
FMain := AViewModel
as TMainViewModel;
inherited;
end;
procedure TMainView.DetachFromViewModel( AViewModel: TViewModelBase );
begin
inherited;
FMain :=
nil;
end;
procedure TMainView.SomeActionActionExecute(Sender: TObject);
begin
inherited;
// Command im ViewModel ausführen
FMain.Reference.SomeActionCommand.Execute;
end;
procedure TMainView.SomeActionActionUpdate(Sender: TObject);
begin
inherited;
TAction( Sender ).Enabled := FMain.IsAssigned
and FMain.Reference.SomeActionCommand.CanExecute;
end;
procedure TMainView.ViewModelPropertyChanged( Sender: TObject;
const e: TPropertyChangedArgs );
begin
inherited;
if FMain.IsAssigned
then
begin
if e.Matches( ['
Active', '
DisplayName'] )
then
begin
Caption := FMain.Reference.DisplayName + '
(' + IfThen( FMain.Reference.Active, '
Active', '
Inactive' ) + '
)';
end;
if e.Match( '
Activity' )
// reagieren bei Aktivität im ViewModel
then
begin
ActivityCurtain.BringToFront;
ActivityCurtain.Visible := Assigned( FMain.Reference.Activity );
ActivityView1.Visible := Assigned( FMain.Reference.Activity );
ActivityView1.BringToFront;
// ViewModel der View zuweisen
ActivityView1.SetViewModel( FMain.Reference.Activity );
end;
end
end;
end.