Class DataViewModel
A view model whose state is data rather than code: values, collections of rows and commands, each by name, changed from outside with DataViewChanges, and reporting what the person does as events.
public sealed class DataViewModel : ViewModel, IViewModel, IDataContext, INotifyPropertyChanged, IDynamicDataContext
- Inheritance
-
DataViewModel
- Implements
- Inherited Members
Remarks
For a view whose behaviour lives somewhere the client does not run -- a server's plugin, whose window has its markup in the plugin and its logic on the server. The game turns its own messages into changes and the events into its own messages; this knows nothing of either.
It is an IDynamicDataContext, which the binding manager already asks before
reflecting, so a view's {Binding Name} finds a value here by name; a collection is a
list of DataViewRows, each a dynamic context of its own, which a repeater's rows
bind to. A command is offered by name, and a button bound to one not offered does nothing.
A changed value raises PropertyChanged for its name alone. A changed row replaces its
collection with a new list, so the repeater rebuilds; selection and scroll in that repeater go
with the rebuild.
Constructors
DataViewModel(IViewManager, string)
A data view model for the view in viewFile.
public DataViewModel(IViewManager viewManager, string viewFile)
Parameters
viewManagerIViewManagerviewFilestringThe view's file, as PopulateFromFile(string) takes it.
DataViewModel(IViewManager, string, string, UntrustedViewLimits)
A data view model for a view the game did not ship -- a server's -- built from its markup and held to what such a view may do (PopulateFromUntrustedText(string, string, UntrustedViewLimits)).
public DataViewModel(IViewManager viewManager, string markup, string name, UntrustedViewLimits limits)
Parameters
viewManagerIViewManagermarkupstringnamestringWhat the view is called, for the log.
limitsUntrustedViewLimits
Properties
this[string]
A value, collection or command as the view sees it now, or null.
public object this[string name] { get; }
Parameters
namestring
Property Value
MostRows
The most rows a collection keeps; rows past it are not taken, so state from somewhere else cannot make a repeater build without end. 1,000 unless the game says otherwise.
public int MostRows { get; set; }
Property Value
Scope
What the view resolves its images' Source and its {Localize} keys against
besides the game's own; set before the view is built.
public ViewScope Scope { get; set; }
Property Value
Methods
Apply(DataViewChange)
Applies change and raises PropertyChanged for its name. A change
with no name does nothing.
public void Apply(DataViewChange change)
Parameters
changeDataViewChange
Apply(IEnumerable<DataViewChange>)
Applies each change in order. A null list applies nothing.
public void Apply(IEnumerable<DataViewChange> changes)
Parameters
changesIEnumerable<DataViewChange>
BuildView(IViewBuilder)
Builds the view from the markup or the file it was given, with Scope as its scope.
protected override void BuildView(IViewBuilder builder)
Parameters
builderIViewBuilder
TryGetValue(string, out object)
Gets a value, collection or command by name. A command the view offers comes back as a command.
public bool TryGetValue(string propertyName, out object value)
Parameters
Returns
TrySetValue(string, object)
Sets the value of propertyName, as a two-way bound control does when the
player changes it. Raises ValueChanged when the value differs from the one
held. Returns false when the name is empty.
public bool TrySetValue(string propertyName, object value)
Parameters
Returns
Events
CommandInvoked
A command this offers was used.
public event EventHandler<DataViewCommandEventArgs> CommandInvoked
Event Type
ValueChanged
A value was changed through a two-way bound control.
public event EventHandler<DataViewValueEventArgs> ValueChanged