Gorgon
Show / Hide Table of Contents

Interface IDataContext<T>

A data context for a view and IViewModel

Namespace: Gorgon.Editor.UI
Assembly: Gorgon.Editor.API.dll
Syntax
public interface IDataContext<T> where T : class, IViewModel
Type Parameters
Name Description
T

The type of view model to use with the view. Ideally an interface for the view model type should be used here.

Remarks

A data context is used to make the view react to changes to data. This is done by hooking the PropertyChanged, and PropertyChanging events and retrieving the name of the property that has been changed and updating the view by modifying one or more controls on the view. This is the cornerstone of MVVM (Model-View-ViewModel), and the Gorgon Editor uses (a rather bastardized version of) MVVM so the view can react to users changes.

important

This pattern is not completely correct in the editor since WinForms is not really designed to use it, so some liberties have been taken. And, unfortunately, makes the job of building a control for a plug in a little more work. The results are worth it however as the communication lines between view model and view are rigidly enforced and make it easier to maintain for larger code bases.

If you wish to know more about MVVM, please visit here.

This interface must be applied to views that wish to use a IViewModel as a data context.

Properties

| Edit this page View Source

DataContext

Property to return the data context assigned to this view.

Declaration
T DataContext { get; }
Property Value
Type Description
T

Methods

| Edit this page View Source

SetDataContext(T)

Function to assign a data context to the view as a view model.

Declaration
void SetDataContext(T dataContext)
Parameters
Type Name Description
T dataContext

The data context to assign.

Remarks

Data contexts should be nullable, in that, they should reset the view back to its original state when the context is null.

Extension Methods

GorgonDebugExtensions.ValidateObject<T>(T, string)
GorgonNullExtensions.AsNullable<T>(object)
GorgonNullExtensions.IfNull<T>(object, T)
GorgonNullExtensions.IsNull(object)
  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author