🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
AsString
This page was created by Hans.karlsen on 2017-04-05. Last edited by Wikiadmin on 2026-07-29.

You can use the case-sensitive <AsString> pattern to insert a ViewModel value into an action presentation or constraint message; this page is for MDriven Designer users configuring ViewModels.

Use Databind labels for ordinary ViewModel text

For ViewModel presentation and messages that are not action-related, use Databind labels instead of <AsString>. Databind labels replace the former general-purpose use of this pattern in ViewModels.

Keep <AsString> for the remaining action-specific scenarios described below, where you need an action name or constraint message to include the current string representation.

What <AsString> means

<AsString> is a presentation pattern. When MDriven evaluates the presentation or message, it replaces that exact pattern with the relevant string value.

The pattern is case-sensitive. Write <AsString> with the same capitalization. A differently cased pattern, such as <asstring>, is not the same pattern.

For example, an action presentation can combine fixed text with the inserted value:

Open &lt;AsString&gt;

This lets the action name give the user context from the current ViewModel value rather than showing fixed text only.

Use it in action names and constraint messages

Use the pattern when an action presentation or constraint message must describe the item that the user is acting on.

  1. In MDriven Designer, open the ViewModel that contains the action or constraint message.
  2. Edit the relevant presentation or message text.
  3. Add <AsString> where the current string value must appear.
  4. Preserve the exact capitalization of the pattern.
  5. Run the ViewModel and verify that the resolved text identifies the expected item.

For example, a constraint message can include both an instruction and the current value:

The selected value &lt;AsString&gt; cannot be used here

Use a short fixed phrase around the pattern so that the resulting action name or message remains understandable after substitution.

Bind a placed action button presentation in WPF

In the Fat-Client WPF client, a placed action button can bind its presentation to a ViewModel column at the same level. Put the following pattern in the action button's Presentation:

&lt;Column:SomeName&gt;

SomeName is the name of the ViewModel column to use. MDriven interprets this as: find the ViewModel column named SomeName on the same level and bind the action button presentation to it.

For example, if the ViewModel level contains a column named ActionCaption, set the placed action button Presentation to:

&lt;Column:ActionCaption&gt;

The button presentation then follows the value of ActionCaption. The column must be available on the same ViewModel level as the placed action button; a column elsewhere in the ViewModel hierarchy is not selected by this pattern.

Do not confuse this pattern with the OCL operator

The ViewModel pattern <AsString> is not the OCL asString operator. Use OCL asString when an OCL expression must convert a value to its string representation. Its result for objects uses the model's DefaultStringRepresentation.

For example, this OCL expression converts a value to a string result:

123.asString

Read asString for the operator and Default String Representation and asString for object representations and performance considerations. In particular, asString and DefaultStringRepresentation are not subscribed, so avoid using them in expressions that need high performance.

See also