Click here to Skip to main content
15,886,199 members
Articles / Desktop Programming / WPF

Introducing the Model Thread View Thread Pattern

Rate me:
Please Sign up or sign in to vote.
4.93/5 (69 votes)
1 May 2010BSD14 min read 164K   862   172  
Reduce threading code, and increase UI responsiveness with a new pattern extending MVVM.
<?xml version="1.0" encoding="utf-8"?>
<root>
  <!-- 
    Microsoft ResX Schema 
    
    Version 2.0
    
    The primary goals of this format is to allow a simple XML format 
    that is mostly human readable. The generation and parsing of the 
    various data types are done through the TypeConverter classes 
    associated with the data types.
    
    Example:
    
    ... ado.net/XML headers & schema ...
    <resheader name="resmimetype">text/microsoft-resx</resheader>
    <resheader name="version">2.0</resheader>
    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
        <value>[base64 mime encoded serialized .NET Framework object]</value>
    </data>
    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
        <comment>This is a comment</comment>
    </data>
                
    There are any number of "resheader" rows that contain simple 
    name/value pairs.
    
    Each data row contains a name, and value. The row also contains a 
    type or mimetype. Type corresponds to a .NET class that support 
    text/value conversion through the TypeConverter architecture. 
    Classes that don't support this are serialized and stored with the 
    mimetype set.
    
    The mimetype is used for serialized objects, and tells the 
    ResXResourceReader how to depersist the object. This is currently not 
    extensible. For a given mimetype the value must be set accordingly:
    
    Note - application/x-microsoft.net.object.binary.base64 is the format 
    that the ResXResourceWriter will generate, however the reader can 
    read any of the formats listed below.
    
    mimetype: application/x-microsoft.net.object.binary.base64
    value   : The object must be serialized with 
            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
            : and then encoded with base64 encoding.
    
    mimetype: application/x-microsoft.net.object.soap.base64
    value   : The object must be serialized with 
            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
            : and then encoded with base64 encoding.

    mimetype: application/x-microsoft.net.object.bytearray.base64
    value   : The object must be serialized into a byte array 
            : using a System.ComponentModel.TypeConverter
            : and then encoded with base64 encoding.
    -->
  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
    <xsd:element name="root" msdata:IsDataSet="true">
      <xsd:complexType>
        <xsd:choice maxOccurs="unbounded">
          <xsd:element name="metadata">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" />
              </xsd:sequence>
              <xsd:attribute name="name" use="required" type="xsd:string" />
              <xsd:attribute name="type" type="xsd:string" />
              <xsd:attribute name="mimetype" type="xsd:string" />
              <xsd:attribute ref="xml:space" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="assembly">
            <xsd:complexType>
              <xsd:attribute name="alias" type="xsd:string" />
              <xsd:attribute name="name" type="xsd:string" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="data">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
              <xsd:attribute ref="xml:space" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="resheader">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" use="required" />
            </xsd:complexType>
          </xsd:element>
        </xsd:choice>
      </xsd:complexType>
    </xsd:element>
  </xsd:schema>
  <resheader name="resmimetype">
    <value>text/microsoft-resx</value>
  </resheader>
  <resheader name="version">
    <value>2.0</value>
  </resheader>
  <resheader name="reader">
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <resheader name="writer">
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <data name="AdapterInvalidTypeException" xml:space="preserve">
    <value>The object must be of type '{0}' in order to use the current region adapter.</value>
  </data>
  <data name="CannotChangeRegionNameException" xml:space="preserve">
    <value>Cannot change the region name once is set. The current region name is '{0}'.</value>
  </data>
  <data name="CanOnlyAddTypesThatInheritIFromRegionBehavior" xml:space="preserve">
    <value>Type '{0}' does not implement from IRegionBehavior.</value>
  </data>
  <data name="ContentControlHasContentException" xml:space="preserve">
    <value>ContentControl's Content property is not empty. 
    This control is being associated with a region, but the control is already bound to something else. 
    If you did not explicitly set the control's Content property, 
    this exception may be caused by a change in the value of the inherited RegionManager attached property.</value>
  </data>
  <data name="DeactiveNotPossibleException" xml:space="preserve">
    <value>Deactivation is not possible in this type of region.</value>
  </data>
  <data name="DelegateCommandDelegatesCannotBeNull" xml:space="preserve">
    <value>Both the executeMethod and the canExecuteMethod delegates cannot be null.</value>
  </data>
  <data name="HostControlCannotBeSetAfterAttach" xml:space="preserve">
    <value>The HostControl property cannot be set after Attach method has been called.</value>
  </data>
  <data name="ItemsControlHasItemsSourceException" xml:space="preserve">
    <value>ItemsControl's ItemsSource property is not empty. 
    This control is being associated with a region, but the control is already bound to something else. 
    If you did not explicitly set the control's ItemSource property, 
    this exception may be caused by a change in the value of the inherited RegionManager attached property.</value>
  </data>
  <data name="MappingExistsException" xml:space="preserve">
    <value>Mapping with the given type is already registered: {0}.</value>
  </data>
  <data name="RegionBehaviorAttachCannotBeCallWithNullRegion" xml:space="preserve">
    <value>The Attach method cannot be called when Region property is null.</value>
  </data>
  <data name="RegionBehaviorRegionCannotBeSetAfterAttach" xml:space="preserve">
    <value>The Region property cannot be set after Attach method has been called.</value>
  </data>
  <data name="RegionNameCannotBeEmptyException" xml:space="preserve">
    <value>The region name cannot be null or empty.</value>
  </data>
  <data name="RegionNameExistsException" xml:space="preserve">
    <value>Region with the given name is already registered: {0}</value>
  </data>
  <data name="RegionViewExistsException" xml:space="preserve">
    <value>View already exists in region.</value>
  </data>
  <data name="RegionViewNameExistsException" xml:space="preserve">
    <value>View with name '{0}' already exists in the region.</value>
  </data>
  <data name="StringCannotBeNullOrEmpty" xml:space="preserve">
    <value>The provided String argument {0} must not be null or empty.</value>
  </data>
  <data name="ValueNotFound" xml:space="preserve">
    <value>{0} not found.</value>
  </data>
  <data name="ViewNotInRegionException" xml:space="preserve">
    <value>The region does not contain the specified view.</value>
  </data>
  <data name="TypeWithKeyNotRegistered" xml:space="preserve">
    <value>No BehaviorType with key '{0}' was registered.</value>
  </data>
  <data name="HostControlMustBeATabControl" xml:space="preserve">
    <value>HostControl type must be a TabControl.</value>
  </data>
  <data name="HostControlCannotBeNull" xml:space="preserve">
    <value>HostControl cannot have null value when behavior attaches. </value>
  </data>
  <data name="RegionNotInRegionManagerException" xml:space="preserve">
    <value>The region manager does not contain the {0} region.</value>
  </data>
  <data name="CannotRegisterCompositeCommandInItself" xml:space="preserve">
    <value>Cannot register a CompositeCommand in itself.</value>
  </data>
  <data name="CannotRegisterSameCommandTwice" xml:space="preserve">
    <value>Cannot register the same command twice in the same CompositeCommand.</value>
  </data>
  <data name="OnViewRegisteredException" xml:space="preserve">
    <value>An exception has occurred while trying to add a view to region '{0}'. 
    - The most likely causing exception was was: '{1}'.
    But also check the InnerExceptions for more detail or call .GetRootException(). </value>
  </data>
  <data name="UpdateRegionException" xml:space="preserve">
    <value>An exception occurred while trying to create region objects. 
    - The most likely causing exception was: '{0}'.
    But also check the InnerExceptions for more detail or call .GetRootException(). </value>
  </data>
  <data name="RegionCreationException" xml:space="preserve">
    <value>An exception occurred while creating a region with name '{0}'. The exception was: {1}. </value>
  </data>
</root>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Engineer
Switzerland Switzerland
Daniel is a former senior engineer in Technology and Research at the Office of the CTO at Microsoft, working on next generation systems.

Previously Daniel was a nine-time Microsoft MVP and co-founder of Outcoder, a Swiss software and consulting company.

Daniel is the author of Windows Phone 8 Unleashed and Windows Phone 7.5 Unleashed, both published by SAMS.

Daniel is the developer behind several acclaimed mobile apps including Surfy Browser for Android and Windows Phone. Daniel is the creator of a number of popular open-source projects, most notably Codon.

Would you like Daniel to bring value to your organisation? Please contact

Blog | Twitter


Xamarin Experts
Windows 10 Experts

Comments and Discussions